Closed Bug 258033 Opened 20 years ago Closed 20 years ago

Weird behavior for function attached to onload event of window element

Categories

(Core :: XUL, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: minghong, Unassigned)

Details

Attachments

(3 files)

6.55 KB, application/vnd.mozilla.xul+xml
Details
6.09 KB, application/vnd.mozilla.xul+xml
Details
6.49 KB, application/vnd.mozilla.xul+xml
Details
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3

Apparently the onload function cannot read the tree view properly. Please view
the source of the URL attached and look for window.onload = function () { .... }.

Basically the URL contains a <tree>. The items in level 1 of the tree are all
containers. However, I want to use JavaScript to turn some containers off:

          if ( list.view.getCellText( i, "count" ) == "0" )
          {
            list.view.getItemAtIndex( i ).setAttribute( "container", "false" );
          }

I found that if I add an alert anywhere inside the function, it will work
properly, e.g.:
          alert( list.view.getCellText( i, "count" ) == "0" );
          if ( list.view.getCellText( i, "count" ) == "0" )
          {
            list.view.getItemAtIndex( i ).setAttribute( "container", "false" );
          }

This is weird. Maybe something related to bug 196057?

Reproducible: Always
Steps to Reproduce:
1. Visit http://blog.cs.cityu.edu.hk/users/50307104/index.xul

Actual Results:  
No changes.

Expected Results:  
Look for items with "writebacks" of "0". The script should set the container
attribute of these items to "false". i.e. Remove the [+] icons of those items.
Attached file The expected result
Please ignore the alert windows as it is a workaround... :-(
> Maybe something related to bug 196057?

Does the bug go away if you remove the iframe?  If so, this is almost certainly
a duplicate of bug 196057.... Marking dependent for now.
Depends on: 196057
Attached file Without iframe
I've taken out the iframe. But it still doesn't work. So this shouldn't be
related to bug 196057. (Sorry, my mistake)

By the way, if it has iframe, the following code will gives 2 alerts:
window.onload = function( event ) {
  alert( event.target );
}

They are "null" and "[object XULDocument]" respectively.
No longer depends on: 196057
The tree functions changed between FireFox/1.7 and 1.8a; your code won't work
with the trunk. If you want your code to work in both platforms, you'll need
something along these lines:

var column = "count";
if ("columns" in list)
  column = list.columns[column];

...

if (list.view.getCellText(i, column) == "0")
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
list.columns doesn't seem to exist, because alert( list.columns ) gives me
"undefined".

Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3

And why ("columns" in list)? There is no element with an ID of "columns".

By the way, free feel to mark this bug as "invalid", if it is the problem of the
script but not the XUL engine.
Attached file The original XUL
Thanks Enn for the explanation:
http://xulplanet.com/forum/viewtopic.php?p=3045#3045

So it IS a (duplicated) bug after all.
I tested the XUL under Mozilla 1.8a3 again:
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8a3) Gecko/20040817

Now I understand why you add ("columns" in list): to check if list.columns exists...

However, API of getCellText() seems to be different:

Error: [Exception... "Could not convert JavaScript argument arg 1
[nsITreeView.getCellText]"  nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"
 location: "JS frame :: http://blog.cs.cityu.edu.hk/users/50307104/xulbrowser.js
:: init :: line 15"  data: no]
Source File: http://blog.cs.cityu.edu.hk/users/50307104/xulbrowser.js
Line: 15

I guess the patch is only checked in the nightly, but not alpha 3?
Component: XP Toolkit/Widgets: XUL → XUL
QA Contact: xptoolkit.widgets
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: