Weird behavior for function attached to onload event of window element

RESOLVED INVALID

Status

()

Core
XUL
RESOLVED INVALID
14 years ago
10 years ago

People

(Reporter: Ng Ming Hong, Unassigned)

Tracking

Trunk
x86
Windows 2000
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(3 attachments)

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
(Reporter)

Description

14 years ago
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.
(Reporter)

Comment 1

14 years ago
Created attachment 157903 [details]
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
(Reporter)

Comment 3

14 years ago
Created attachment 157930 [details]
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.
(Reporter)

Updated

14 years ago
No longer depends on: 196057

Comment 4

14 years ago
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
Last Resolved: 14 years ago
Resolution: --- → INVALID
(Reporter)

Comment 5

14 years ago
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.
(Reporter)

Comment 6

14 years ago
Created attachment 157942 [details]
The original XUL
(Reporter)

Comment 7

14 years ago
Thanks Enn for the explanation:
http://xulplanet.com/forum/viewtopic.php?p=3045#3045

So it IS a (duplicated) bug after all.
(Reporter)

Comment 8

14 years ago
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?

Updated

10 years ago
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.