2

I have two frames in a frameset - frame[0] contains a script that loads a page into frame[1] using

top.frames[1].location.href = 'http://some_location.com/page.html';

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

Is there a way to do this?

3 Answers 3

3

use onload event of FRAME element

edit:

<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' )";

or

<frame src = '/dummyInitial.html' onload = "if( top.frames[1].location.pathname != '/dummyInitial.html' " ) alert( 'loaded' )";
4
  • Could you expand on that? If I use top.frames[1].location.href = 'ongar.org/mypage.html'; top.frames[1].onload(alert('loaded')); I get the alert before mypage.html has loaded, because there is already a page in frame[1]. I'd like the alert after mypage.html has fully loaded. Aug 5, 2009 at 9:11
  • True, but in the example above you missed out the clause checking the location.pathname value of the new page. Aug 5, 2009 at 9:22
  • onload events in iframes are sort of useless- they are very inconsistent across browsers, even within a browser understanding why onload is firing can be messy. Use with caution!
    – mixonic
    Aug 5, 2009 at 12:02
  • @mixonic: if only the question was about iframes.
    – palindrom
    Aug 5, 2009 at 12:08
0

Well I do this, and it works.

var idInterval;
function callPage()
{   top.main.document.location.href = somepage.aspx;
    document.getElementById('divLoading').style.visibility ="visible";
    idInterval = setInterval("validaFrameMain()",50);
}
//look if the frame page is complete load
function validaFrameMain()
{
  if (top.main.document.readyState != "complete")
  {document.getElementById('divLoading').style.visibility ="visible";}
  else
  { document.getElementById('divLoading').style.visibility ="hidden";;
    clearInterval(idInterval);
    idInterval = nothing;
  }
}
0

If you have no control over the loaded page's source and more importantly, if it is coming from another domain, then there is only one answer:

You can't.

Interframe communication between different domains is NOT possible. And you need interframe communication because you would need something like jquery's ready function in the loaded page to determine if the entire page (the DOM) is loaded.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.