views:

532

answers:

1

This should subscribe function "handler" on scroll events from every iframe on the page

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
}

... but on some pages it doesnt. Furthermore, in those cases anything in contentDocument is inaccessible, and without unwrapping contentDocument is null. Using FF 3.5

UPD iframe content and page are from the same domain

+2  A: 

If the page in the iframe is from a different domain that the page containing the iframe, then you do not have access to the DOM of the iframe. This is a security feature.

Marius
thanks! i havent thought about it, but in case of same-domain pages the trouble isnt gone