检测子窗口何时加载“每个”窗口是时候这样做了
我正在尝试使用 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
事件“注释行”,但似乎 父窗口仅检测第一个子加载。
所以流程应该是这样的:
父级打开子级
父级检测子级负载
家长重定向孩子
父级再次检测子级负载
。 。 等等,
- 我拥有共享相同域和协议的两个页面。
- 不应在子窗口上执行任何 JS“即子窗口无法检查其加载并将数据传递给父窗口”。
I am trying to add some page load-checking functionality to a parent,child windows using Javascript.
My goal is to detect "from the parent window", each time the child window fully loads then execute some code.
I use the following code sample on my parent window :
<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>
The previous Code attaches and detects load event to my child window, then it redirect it to another page "after I click the confirm button",
What I want to do is to make the parent window detects the next child loads,
i.e. detect the load after the redirect.
I tried to remove, then re-attach a new onload
event "the commented lines", but it seems the
parent window detects the First child-load only.
So the flow should go like:
Parent opens Child
Parent detects Child load
Parent redirect the child
Parent detects again the child load
.
.
and so on
- I own the two pages which share the same domain and protocol.
- No JS should be executed on the child window "i.e. child window can't check it's loads and pass data to parent window".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导致孩子导航后重新绑定是否不起作用?
Did re-binding after causing the child to navigate not work?