window.open/window.navigate - how to tell when the URL has completed loading

R

Richard Bell

Newbie question ... please respond to group

I'm trying to open/navigate to a url. How can I tell when the page is
fully loaded? Testing suggest that window.open returns before the
page is completely loaded and displayed. Likewise, window.navigate.
The code looks something like this:

wHandle = window.open( url, name, flags );
....
// how to tell when url is fully loaded and displayed
....
wHandle.navigate( url );
....
// how to tell when url is fully loaded and displayed
....

I've tried setting wHandle.onload but that code does not seem to be
executing.

I'm stumped.

Thanks.
 
E

Erwin Moller

Richard said:
Newbie question ... please respond to group

I'm trying to open/navigate to a url. How can I tell when the page is
fully loaded? Testing suggest that window.open returns before the
page is completely loaded and displayed. Likewise, window.navigate.
The code looks something like this:

wHandle = window.open( url, name, flags );
...
// how to tell when url is fully loaded and displayed
...
wHandle.navigate( url );
...
// how to tell when url is fully loaded and displayed
...

I've tried setting wHandle.onload but that code does not seem to be
executing.

I'm stumped.

Thanks.

Hi Richard,

Yes, that can be a problem, especially when the second page need some time
to load (serverside activity eg.)
A reliable way is to put a little script at the end of the page you are
loading that calls some javascriptfunction in the first window.

something like this:

page1.htm (the first window):

<script type="text/javascript">
var page2Loaded = false;
function IAmLoaded(){
page2Loaded = true;
alert("Page2 loaded!");
}
</script>


page2.htm (the long second window)

..... (long calculations or long page)...
at the end:
<script type="text/javascript">
opener.IAmLoaded();
// or was it opener.document.IAmLoaded() ?? test that. :p
</script>
</body>
</html>

even better could be:
<script type="text/javascript">
setTimeout("opener.IAmLoaded()" , 1000);
</script>

so you give the browser an extra second to finish the </body> and </html>
tag.

Alternatively you could also poll the second page from page1 for the
existance of some function you define at the end of that second page, but I
think the first method is easier.

Hope this helps.
Regards,
Erwin Moller
 
R

Richard Bell

Erwin,

Thanks for the clue. Unfortunately, I have no control over the pages
I am loading so adding script to those pages is not an option.

Since my original post, I've done some more investigation and it would
appear that using wHandle.document.readystate may be an option under
IE 6 (but not other browsers). Also wHandle.addEventListner( "load",
func_to_execute_when_window_loaded, false); would appear to have
potential (it may be wHandle.document.addEventListner(...), I'm not
sure). Unfortunately, attempts to use either of these techniques are
getting me in trouble. When I reference wHandle.document IE seems to
just go away. I'm able to move the windows, close them, etc. but
nothing in the javascript seems to be happening (including debug
statements).

If anyone out there has any insight, I'd very much appreciate a clue
regarding either the issue with referencing

wHandle = window.open( url, name, flags );
....

// is this an ok reference?
if (wHandle.document.readystate...){}
....
// how does this work (anyone have an example that does)
wHandle.document.addEventListner( "load", loadfunc, false);
....

Thanks,
Richard
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top