从 IFrame 中访问父窗口的 document.body

发布于 2024-07-30 10:08:36 字数 227 浏览 2 评论 0原文

我在 iframe 中有一个脚本,用于侦听 document.body 中鼠标的移动,如下所示:

$(document.body).addEvent('mousemove',this.refresh.bind(this));

这在 IFrame 内工作得很好,但我还想跟踪鼠标是否被移动到 Iframe 之外。 无论如何要这样做吗? 我正在使用 MooTools。

I have a script in an iframe that listens for movements of the mouse from document.body as follows:

$(document.body).addEvent('mousemove',this.refresh.bind(this));

This works fine from within the IFrame, but I want to also track that the mouse is being moved outside of the Iframe. Anyway to do this? I am using MooTools.

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

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

发布评论

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

评论(1

神也荒唐 2024-08-06 10:08:36

iframe 中的脚本可能会也可能不会被允许访问父级。 如果父级位于同一域中,则会。

在这种情况下,您应该能够使用如下内容:

$(parent.document.body).addEvent('mousemove',this.refresh.bind(this));

这将捕获父窗口内的任何鼠标移动。 “parent”是“window”的一个属性,它是对父 iframe 的“window”对象的引用。

The script in your iframe may or may not be allowed access to the parent. If the parent is in the same domain, it will.

In that case, you should be able to use something like this:

$(parent.document.body).addEvent('mousemove',this.refresh.bind(this));

This would capture any mouse movement within the parent window. "parent" is a property of "window" that is a reference to the "window" object of the parent iframe.

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