473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
2 8278
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
2
by: Jawahar Rajan | last post by:
All, I have a printer friendly page that is opened when a user clicks a link on my page to get the printer friendly version, How ever when they close out the printer friendly version and return to...
5
by: Nicola Pedrozzi | last post by:
Here I really need a guru... ;^( I found out today with a big disappointment that : window.open("url", ...) and also navigate("url") limit the max length of the url string to something...
9
by: Christopher Benson-Manica | last post by:
I have the following situation: Page A opens a window named 'foo'. Page A then reloads itself. Is there a way for the reloaded Page A to determine whether there is an open window named 'foo',...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
21
by: alistair_henderson | last post by:
Morning All, I have some code for a website which uses 'window.open' to simulate modal dialog boxes. I use the window.closed property to decide if the window object exists at various points. ...
6
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
18
by: Csaba Gabor | last post by:
Is there a straightforward way of implementing a PHP equivalent to window.setTimeout? In a javascript web app, it's often the case that things are done on an event driven basis. For example,...
1
by: alnino | last post by:
Hi, On a form I have a command button that allows a user to browse for a file (PDF, Word, etc…). This command button then stores a hyperlink to the file within an associated txtfield in the table....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.