problem reading DOM after window.open with url

J

John Derry

I'm having a curious problem. I open a window with window.open method
and supply a url which is a local file of file:/// form. After that, I
go into the document of this new window to read the DOM for multiple
forms which are defined in the html. The problem is that the objects are
not immediately there. To make them available, I've found that if I do a
View, Source from the new window's menu bar, THEN the DOM forms are
there as expected.

I'm using Mozilla 1.7.3; maybe it's my browser version. Problem with
using Firefox for me, the access to local content is limited. I tried
the change to the configuration that is supposed to allow this, but it
didn't work.
 
R

RobG

John said:
I'm having a curious problem. I open a window with window.open method
and supply a url which is a local file of file:/// form. After that, I
go into the document of this new window to read the DOM for multiple
forms which are defined in the html. The problem is that the objects are
not immediately there. To make them available, I've found that if I do a
View, Source from the new window's menu bar, THEN the DOM forms are
there as expected.

You may be trying to read the document before it's finished loading.
Some suggestions:

1. Have the new document set a variable onload. Use setTimeout to
check for the variable every 200ms or so until it's available, then do
stuff. Set a limit on the number of re-tries.

2. Have a function in the new page run onload to call the function in
the parent page that does stuff.

3. Guess at how long it will take to load the new page and use
setTimeout to wait that long before starting to process it. Check that
elements exist before trying to do anything with them.

Option 1 is OK, 2 is reasonably elegant, 3. is pretty awful.
 
J

John Derry

RobG said:
You may be trying to read the document before it's finished loading.
Some suggestions:

1. Have the new document set a variable onload. Use setTimeout to
check for the variable every 200ms or so until it's available, then do
stuff. Set a limit on the number of re-tries.

2. Have a function in the new page run onload to call the function in
the parent page that does stuff.

3. Guess at how long it will take to load the new page and use
setTimeout to wait that long before starting to process it. Check that
elements exist before trying to do anything with them.

Option 1 is OK, 2 is reasonably elegant, 3. is pretty awful.
You are absolutely right. While I'm waiting for the browser to get the
window open, my script has plowed ahead. I can loop until I see the flag
that I set, in onLoad event handler associated with the window, but
that is too long and the browser complains my script is taking too long.

Thanks alot for the help,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top