我试图添加一些页面加载检查功能到父窗口,子窗口使用Javascript。
我的目标是检测“从父窗口”,每次子窗口完全加载,然后执行一些代码。
我在父窗口上使用以下代码示例:
<script type='text/javascript'>
childPage=window.open('http://www.example.com');
childOnLoad=childPage.addEventListener('load', LoadAndGo, true);
function LoadAndGo()
{
if(confirm("Press a button")==true)
{
//childPage.removeEventListener ("load", childOnLoad, false);
childPage.top.location.href="http://www.example.com";
//childOnLoad=childPage.addEventListener('load', LoadAndGo, true);
}
}
</script>前面的代码附加并检测加载事件到我的子窗口,然后它将其重定向到另一个页面“在我单击确认按钮之后”,
我想要做的是让父窗口检测下一个子负载,即在重定向之后检测负载。
我尝试删除,然后重新附加一个新的onload事件“注释行”,但似乎父窗口只检测到第一个子加载。
所以流程应该是这样:
父母开启孩子
父检测子负载
父母重定向孩子
父级再次检测子负载。
。。诸若此类
发布于 2011-08-24 23:13:16
在导致子导航不工作后,是否重新绑定?
<script type='text/javascript'>
var childPage = window.open('http://www.example.com');
childPage.addEventListener('load', LoadAndGo, true);
function LoadAndGo()
{
if(confirm("Press a button") == true)
{
childPage.top.location.href = "http://www.example.com";
// Re-bind
childPage.addEventListener('load', LoadAndGo, true);
}
}
</script>https://stackoverflow.com/questions/7183291
复制相似问题