【问题标题】:Catching events from Iframe in Firefox在 Firefox 中从 iframe 捕获事件
【发布时间】:2009-08-18 13:26:41
【问题描述】:

这应该订阅页面上每个 iframe 的滚动事件的“处理程序”函数

var iframes = document.getElementsByTagName("iframe");
for (i = 0; i < iframes.length; i++) {
  var current = getRealObject(iframes[i])
  current.contentDocument.addEventListener('DOMMouseScroll', handler, false)      
}

function getRealObject(object) {  // unwraps the object if necessary
  return (object.wrappedJSObject) ? object.wrappedJSObject : object
}

...但在某些页面上却没有。此外,在这些情况下, contentDocument 中的任何内容都无法访问,并且如果不展开 contentDocument 则为空。使用 FF 3.5

UPD iframe 内容和页面来自同一个域

【问题讨论】:

    标签: javascript firefox events iframe


    【解决方案1】:

    如果 iframe 中的页面与包含 iframe 的页面来自不同的域,则您无权访问 iframe 的 DOM。这是一项安全功能。

    【讨论】:

    • 谢谢!我还没有考虑过,但是在同域页面的情况下,问题并没有消失
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多