javascript clearTimeout 在子页面中不起作用
这些是相关的行。
// In the parent page I set the timer and attach its handle to the window
window.warnTo = window.setTimeout("WarnTimeout();", 20000);
// If I clear the timer in the same page it works great
window.clearTimeout(window.warnTO);
// In the child page launched with window.open,
// I try to clear the timer and the timer still fires
window.opener.clearTimeout(window.opener.warnTO);
所有变量似乎都已设置,并且 window.opener 似乎是父窗口。 我很困惑。
These are the relavent lines.
// In the parent page I set the timer and attach its handle to the window
window.warnTo = window.setTimeout("WarnTimeout();", 20000);
// If I clear the timer in the same page it works great
window.clearTimeout(window.warnTO);
// In the child page launched with window.open,
// I try to clear the timer and the timer still fires
window.opener.clearTimeout(window.opener.warnTO);
All variables appear to be set and window.opener appears to be the parent window.
I'm stumped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用 opener 属性访问该页面?
这是我用于测试此功能的示例代码。我使用 Interval 而不是 Timeout 来更清楚地表明它的工作原理:
Opener.html
Opened.html
UPDATE
正如您在评论中指出的那样,您提供的代码示例中也有一个拼写错误。
将
warnTO
更改为warnTo
。Have you tried to access the page using the opener property?
Here's my sample code for testing this. I use Interval rather than Timeout to give a clearer indication of it working:
Opener.html
Opened.html
UPDATE
As you pointed out in the comments, you've also got a typo in the code sample you've provided.
Change
warnTO
towarnTo
.