jQuery iframe滚动事件(IE) [英] jQuery iframe scroll event (IE)
本文介绍了jQuery iframe滚动事件(IE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法在Internet Explorer 7中收听滚动事件。
Can't listen to the scroll event in Internet Explorer 7.
我尝试过:
$("#myIframe").scroll(function() { alert('hi'); })
适用于FF:
$($("#myIframe").contents().get(0)).scroll(function() { alert('hi'); })
让按键工作:
$($("#myIframe").contents().get(0)).keydown(function() { alert('hi'); })
推荐答案
尽管我喜欢jQuery。我不能让这个工作。但是,我在普通的旧javascript中尝试了这个,它在IE,FF,Safari和Chrome中运行得很好。
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>
编辑:使用窗口时,以下适用于FF,Safari和Chrome 。加载()。使用document.ready时它只适用于FF。无论出于何种原因,在任何一种情况下它都无法在IE8中运行。
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');
});
});
这篇关于jQuery iframe滚动事件(IE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文