Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

javascript - jQuery iframe scroll event (IE)

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'); })
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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');
    }); 
}); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...