【发布时间】:2014-12-18 09:06:45
【问题描述】:
我正在使用 iframe 加载外部 URL。这是结构 -
<iframe id="iframe-wrapper" src="http://blog.kpmg.ch/" style="width: 100%; height: 100%; overflow-y: scroll"></iframe>
当我滚动浏览 iframe 内容时,我正在尝试做一些事情。我尝试了各种方法,都没有奏效。以下是我已经尝试过的一些事情 -
1) jQuery iframe scroll event (IE)
$(window).load(function(){
$($('#iframe-wrapper').contents()).scroll(function(){
alert("Scrolling");
});
});
2)jQuery iframe scroll event (IE)
$('#iframe-wrapper').load(function(){
$($(this)[0].contentWindow).scroll(function(){
alert("Scrolling");
});
});
$("#iframe-wrapper").load(function(){
var iframeContent = getFrameTargetElement( document.getElementById("iframe-wrapper") );
iframeContent.onscroll = function(e){
alert("Scrolling");
};
});
4) Jquery and binding an event to an iframe
$("#iframe-wrapper").load(function(){
$("#iframe-wrapper").contents().find("body").scroll( function(e) {
alert("Scrolling");
});
});
【问题讨论】:
-
$("#iframe-wrapper").scroll(fn);你试过了吗? -
duplicate 是您没有见过或尝试过的东西,它可以工作!我已经尝试了链接,检查我展示的第三个示例,如果你能在我做错的地方请帮助我。在完成并理解完整问题之前不要找到重复项。 :)
-
@Jai,是的,我已经尝试过了,但对我不起作用。我不知道这里出了什么问题。我发现在 iframe 完全加载后应该绑定事件的地方。所以我不再那样尝试了。
-
@Shuvro 您是否考虑过您的问题可能在于调用 alert() 函数,而不是 iframe 本身?你看过这个stackoverflow.com/questions/12139953/…
-
@KhalidT。感谢您指出这一点。但我已经尝试过这种方式。也没有用。 :)
标签: javascript jquery html iframe