views:

2272

answers:

2

Can't listen to the scroll event in Internet Explorer 7.

I've tried:

$("#myIframe").scroll(function() { alert('hi'); })

Works for FF:

$($("#myIframe").contents().get(0)).scroll(function() { alert('hi'); })

Getting keypresses work:

$($("#myIframe").contents().get(0)).keydown(function() { alert('hi'); })

+3  A: 

As much as I love jQuery. I can't get this to work. However, I tried this in plain old javascript and it worked just fine in IE, FF,Safari and Chrome.

<script type="text/javascript">
    window.onload = function() {
      var frm = document.getElementById("myIframe").contentWindow;
      frm.onscroll = function(){
        alert("EUREKA");
      }
    }
</script>

EDIT: The following works in FF, Safari and Chrome when using window.load(). When using document.ready it only works in FF. For whatever reason it doesn't work in IE8 in either event.

$(window).load(function(){
    $($('#myIframe').contents()).scroll(function(){
       alert('frame scrolled in jquery');
    }); 
});
Jose Basilio
works perfect, thanks!
Great. Please accept my answer.
Jose Basilio
A: 

Put this on the parent:

var childScrollHandler = function () { alert('Scrolling going on'); }

And Put then this on the iframe content

$(document).bind('scroll', function(ev){ parent.childScrollHandler(ev); });

replace $(document) by whatever element you are trying to listen into