【问题标题】:Accessing document.body of parent window from within IFrame从 IFrame 中访问父窗口的 document.body
【发布时间】:2009-07-31 20:54:17
【问题描述】:

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

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

这在 IFrame 内可以正常工作,但我还想跟踪鼠标是否被移出 Iframe。无论如何要这样做?我正在使用 MooTools。

【问题讨论】:

    标签: iframe mootools parent-child


    【解决方案1】:

    您的 iframe 中的脚本可能会或可能不会被允许访问父级。如果父级在同一个域中,它会。

    在这种情况下,你应该可以使用这样的东西:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-05
      • 2018-12-18
      • 2013-08-30
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      相关资源
      最近更新 更多