检测 javascript 是否正在框架中执行
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
框架与其所有者在同一线程上运行。您可以通过让子框架运行长循环,同时父框架在短计时器上执行一些代码来验证这一点 - 您会注意到父框架的计时器必须等到循环结束才能执行其回调。
这意味着子框架及其父框架不能同时执行脚本。在子框架中的 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.