如何检测跨域弹窗或 iframe 是否加载完成?

发布于 2024-12-08 04:04:43 字数 624 浏览 2 评论 0 原文

我正在打开一个与主机不同的域的新窗口。 我想在完成后开始推送 URL 片段。 我已经尝试过这个...

<script type="text/javascript">
<!--
function checkPage() {
if (windowReference.document.readyState == 'complete') {
alert('Done')
return;
}
setTimeout('checkPage()',100);
}

var windowReference = window.open('popup.htm','WindowName');

setTimeout('checkPage()',100);
//-->
</script>

信用:http://www.codingforums .com/archive/index.php/t-58396.html

但由于弹窗是跨域的,主机无法访问windowReference.document

还有其他办法吗?

I'm opening a new window of a different domain from the host.
I want to start pushing URL fragments when it's done.
I've tried this...

<script type="text/javascript">
<!--
function checkPage() {
if (windowReference.document.readyState == 'complete') {
alert('Done')
return;
}
setTimeout('checkPage()',100);
}

var windowReference = window.open('popup.htm','WindowName');

setTimeout('checkPage()',100);
//-->
</script>

Credit: http://www.codingforums.com/archive/index.php/t-58396.html

But as the popup is cross-domain, the host cannot access windowReference.document.

Any other way around?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事未完 2024-12-15 04:04:43

这是不可能的,您无法控制 dom(文档),因此不可能监听弹出窗口的任何事件。

It's not possible, you do not have control over the dom (document), so it's not possible to listen to any events of the popup.

三五鸿雁 2024-12-15 04:04:43

附加在主机窗口上的调整大小事件并通过弹出来更改宽度或高度 + 或 - 1 来触发调整大小怎么样?它可以在完全最大化的窗口上运行吗?

What about attaching on resize event on the host window and change width or height + or - 1 by from pop to trigger resize? Will it work on fully maximized window?

無處可尋 2024-12-15 04:04:43

只需使用PostMessage进行跨域通信即可。

Just use PostMessage for cross-domain communication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文