我在一个框架集中有两个框架 -frame[0]
包含一个加载页面的frame[1]
脚本
top.frames[1].location.href = 'http://some_location.com/page.html';
然后在该页面上执行操作,例如在页面内搜索文本。在执行此操作之前,我需要脚本等到page.html
第二帧加载,并且我无法onload=...
在第二页中使用,因为我无法控制它的源。
有没有办法做到这一点?
我在一个框架集中有两个框架 -frame[0]
包含一个加载页面的frame[1]
脚本
top.frames[1].location.href = 'http://some_location.com/page.html';
然后在该页面上执行操作,例如在页面内搜索文本。在执行此操作之前,我需要脚本等到page.html
第二帧加载,并且我无法onload=...
在第二页中使用,因为我无法控制它的源。
有没有办法做到这一点?
使用 FRAME 元素的 onload 事件
编辑:
<frame onload = "if( top.frames[1].location.pathname == '/page.html' " ) alert( 'loaded' )";
或者,如果您将不同的页面加载到同一框架,请使用:
<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' )";
如果您无法控制加载页面的来源,更重要的是,如果它来自另一个域,那么只有一个答案:
你不能。
不同域之间的帧间通信是不可能的。而且您需要帧间通信,因为您需要在加载的页面中使用类似 jquery 的 ready 函数来确定是否加载了整个页面(DOM)。
好吧,我这样做了,并且有效。
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;
}
}