Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: help! problems after window.open()

8 views
Skip to first unread message

Benjamin Smedberg

unread,
Apr 2, 2012, 5:09:43 PM4/2/12
to bootstrap, dev-ext...@lists.mozilla.org
On 4/1/2012 10:52 PM, bootstrap wrote:
> In
> Now, back in the function that calls win = window.open(), there is a
> tiny bit of sense, but not much. After that win = window.open()
> function call, win.name does contain the name of the window supplied
> in the second argument of window.open(). A miracle! However...
>
> win.document.getElementsByTagName("html").length // returns 1 ==
> correct
> win.document.getElementsByTagName("body").length // returns 1 ==
> correct
> win.document.getElementsByTagName("font").length // returns 0 ==
> WRONG --- should be 1
At what point are you making these calls? Note that immediately after
you create the window using window.open, it only has about:blank loaded
into it. The URL you specified has not yet loaded into it. So AFAICT the
answers you are getting are correct. You can probably add a load
listener to the window and then when you do receive a load notification,
win.document will have your new page loaded into it.

--BDS

bootstrap

unread,
Apr 2, 2012, 7:08:54 PM4/2/12
to
PS: I didn't see my message appear for over a day, so I posted
a new message just a while ago (with somewhat more details).
But let me answer your specific questions below.

To test my code, I create event listeners for "window.load" and
"mousedown" events.

Inside my "mousedown" event handler function I capture the
screenX, screenY of the mouse cursor from the event structure,
then create a path string, a feature string, then call

win = window.open(pathstring, "clarify", featurestring);

Note that the pathstring refers to an HTML file on my ubuntu64
linux filesystem, so it is something like the following:
"file://home/max/firefox/extension/meanings/content/clarify.html"

Now, I have dozens of print statements in these TWO places:
#1: inside my "window load" event handler function.
#2: inside my "mousedown" event listener function.

#2 is immediately following my window.open() call.

Inside #1, I take the event argument and work through
every conceivable element to attempt to find a window
with name == "clarify" (as set by window.open()).
I am unable to find such a window, and the windows
I do find have no name, and no <p> tags or id = "clarify".

The print statements at #2 are a bit simpler, because
I have the win variable, which is supposed to be the
reference to the window created by window.open()
according to the window.open() documentation.
But I go through every possible permutation trying
to find another window that has a <p> tag or has
an id = "clarify" (which is in the loaded HTML file).

Also note this. As we would expect, since javascript
is essentially a single-thread model, my printouts
confirm that BEFORE my window.open() call returns,
my installed "window load" event handler function is
called by javascript. Therefore, the window is already
fully loaded before my printouts mentioned in #2 above.
And, in fact, the window should be fully loaded before
my printouts mentioned in #1 above too.

Therefore, you assumption is wrong. The HTML file
is fully loaded when the lines following window.open()
are executed. At least that is DEFINITELY how this
works on my ubuntu64 system works (firefox v11), as
demonstrated by the order of my printout statements.

The bottom line is, I am already doing what you
suggest IN ADDITION TO the same tests after
the window.open() function call. So that doesn't
explain what my problem is.

Any other ideas?

bootstrap

unread,
Apr 2, 2012, 9:06:45 PM4/2/12
to
>  Any other ideas?- Hide quoted text -
>
> - Show quoted text -

Here is an update that only serves to make the
twilight zone music louder and more crazy.

If I add the following line immediately after the
window.open() function call, then everything
works as it should (as would be expected):

alert("bogus alert message");

Of course I need to cancel the alert dialogs
before the code continues on (presumably),
and that somehow makes things work.

Notice that I tried adding the following line
in place of the alert() call, and it did not
change anything:

win.location = url; // url == path to loaded file

In fact, after that line the following line returns
"about:blank" (unless the alert() line exists):

win.location = url;

Freaking hell! What is going on inside this
crazy javascript/mozilla/DOM or whatever...
is completely psycho. This behavior is just
absolutely, positively crazy insane. HELP.

Dave Townsend

unread,
Apr 2, 2012, 11:02:10 PM4/2/12
to
On 04/02/12 16:08, bootstrap wrote:
> Also note this. As we would expect, since javascript
> is essentially a single-thread model, my printouts
> confirm that BEFORE my window.open() call returns,
> my installed "window load" event handler function is
> called by javascript. Therefore, the window is already
> fully loaded before my printouts mentioned in #2 above.
> And, in fact, the window should be fully loaded before
> my printouts mentioned in #1 above too.
>
> Therefore, you assumption is wrong. The HTML file
> is fully loaded when the lines following window.open()
> are executed. At least that is DEFINITELY how this
> works on my ubuntu64 system works (firefox v11), as
> demonstrated by the order of my printout statements.

This is in general not correct, window.load returns as soon as it has
started the load of the window you request but even files on the local
system are still loaded asynchronously and so normally the window
wouldn't be properly loaded until the load event fires, but you say
you're seeing that which is extremely odd. Can you show us the code
you're using? I'd expect something like this to work fine:

var win = window.open(pathstring, "clarify", featurestring);
win.addEventListener("load", function() {
// you can access win and win.document fully here.
}, false);

bootstrap

unread,
Apr 3, 2012, 10:07:27 PM4/3/12
to
> }, false);- Hide quoted text -
>
> - Show quoted text -

Okay, I created a stripped-down version of the extension
that only contains statements to print-to-error-console to
show the values of relevant variables. You can download
the files here: www.iceapps.com/meanings20120402.zip
0 new messages