Keir Finlow-Bates Keir Finlow-Bates - 1 year ago 93
Javascript Question

How to get javascript in one frame to wait until a page has loaded in a second frame

I have two frames in a frameset -

contains a script that loads a page into

top.frames[1].location.href = '';

and then performs actions on that page, for example searching text within the page. I need the script to wait until
has loaded in the second frame before doing this, and I can't use
in the second page because I have no control over its source.

Is there a way to do this?

Answer Source

use onload event of FRAME element


<frame onload = "if( top.frames[1].location.pathname == '/page.html' " ) alert( 'loaded' )";

or if you load different pages to the same frame use this:

<frame onload = "if( top.frames[1].location.pathname != 'about:blank' " ) alert( 'loaded' )";


<frame src = '/dummyInitial.html' onload = "if( top.frames[1].location.pathname != '/dummyInitial.html' " ) alert( 'loaded' )";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download