我在这个问题上遇到了困难,尽管互联网上很多人似乎都有同样的问题,但网上没有任何解决方案对我有用。
我有以下 html 代码:
<iframe id="documentIFrame" src='http://localhost:49551//Documents/System/ef4be80c-a8d8-482e-9792-50c5692aa07f.pdf' width='100%' height='100%' frameborder='0'></iframe>
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的以下 js 代码:
1)
$("#documentIFrame").on('load', function () {
var iframe = document.getElementById('documentIFrame');
iframe.contentDocument.addEventListener('scroll', function (event) {
console.log("SCROLL");
}, false);
});
Run Code Online (Sandbox Code Playgroud)
这样就没有显示任何结果,甚至不会进入该函数。
2.
var iframe = $("#documentIFrame").contentWindow;
$(iframe).scroll(function () {
console.log("NOW SCROLLING...");
if ($(iframe).scrollTop() == $(iframe).height() - $("#documentIFrame").height()) {
alert("Reached bottom!");
}
});
Run Code Online (Sandbox Code Playgroud)
和以前一样,没有任何结果。
3)
var iframe = document.getElementById("documentIFrame").contentWindow;
console.log(iframe);
iframe.onscroll = function () {
console.log("scrolling...");
}
Run Code Online (Sandbox Code Playgroud)
一样,没有结果。
编辑:关于此的一些额外信息,在这种情况下,如果我将函数分配给事件之后console.log(),并且我在 中搜索,则事件显示为。iframeonscrolliframeonscrollnull
编辑2:这对你们中的一些人来说可能会派上用场,使用jQuery …