检测 javascript 是否正在框架中执行

发布于 2024-10-03 05:23:04 字数 119 浏览 1 评论 0原文

在 Firefox 中,如果我使用frames[i].document.readyState,即使框架正在执行 Javascript,它也会显示完成。

有没有办法检测 Javascript 是否在框架中执行?

In Firefox if I use frames[i].document.readyState it will say complete even though the frame is executing Javascript.

Is there a way to detect if Javascript is executing in a frame?

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

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

发布评论

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

评论(2

不顾 2024-10-10 05:23:04

框架与其所有者在同一线程上运行。您可以通过让子框架运行长循环,同时父框架在短计时器上执行一些代码来验证这一点 - 您会注意到父框架的计时器必须等到循环结束才能执行其回调。

这意味着子框架及其父框架不能同时执行脚本。在子框架中的 JavaScript 完成执行之前,您的检查不会运行。

Frames run on the same thread as their owner. You can verify this by having a child frame run a long loop whilst the parent has some code executing on a short timer — you'll notice that the parent's timer has to wait until the loop ends before it can execute its callback.

This means that a child frame and its parent cannot execute scripts simultaneously. Your check isn't running until the JavaScript in the child frame has finished executing.

恏ㄋ傷疤忘ㄋ疼 2024-10-10 05:23:04
   var in_iframe = window != window.top;
   var in_iframe = window != window.top;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文