By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Richard Bell wrote:
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
Jul 20 '05 #2

P: n/a
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

On Mon, 09 Feb 2004 13:46:48 +0100, Erwin Moller
<si******************************************@spam yourself.com> wrote:
Richard Bell wrote:
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


Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.