javascript-如何检测 iframe 中的滚动事件? [英] javascript-How to detect scroll event in iframe?

查看:17
本文介绍了javascript-如何检测 iframe 中的滚动事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 iframe 标签添加事件滚动时遇到问题.通常,我使用带有 div 标签的滚动事件它运行良好.但是当我在 iframe 标签中添加滚动事件来检测用户滚动 pdf 页面时,它不起作用.为什么我无法访问 iframe 中的 html 元素?,我有以下代码检查:

I have a problem when I try add event scroll with iframe tage. generally, I use scroll event with div tag It was working well. but when I add scroll event in iframe tag to detect user scroll pdf page, It was not working. why cannot I access html elements in iframe?, I have code inspect below:

我尝试使用 iframe 添加 javascript 滚动事件:

HTML 代码:

<iframe id="myframe" src="doc.pdf"></iframe>

JavaScript 代码:

document.getElementById('myframe').onscroll = function(){
	 	alert('scrolling page');
};

推荐答案

一个iframe没有scroll方法,iframedocumentcode> 确实 - 您需要引用内部 document 而不是