【发布时间】:2018-07-30 23:48:44
【问题描述】:
我的主页中有一个链接,该链接使用 ajax 检索显示在 iframe 中的 PDF,我正在尝试检测 PDF 文档的滚动事件并显示消息或执行某些操作。我在 stackoverflow 和谷歌搜索上尝试了与其他解决方案不同的解决方案,但找不到好的解决方案。
Main.php
<html>
<!--ajax request-->
<script type="text/javascript">
$(document).on('click','#nextpdf',function(event) {
event.preventDefault();
var reg = $(this).attr("href");
var str = reg.split('?')[1];
$.ajax({
type: "GET",
url: '../functions/pdfreader.php',
data: 'pdfxs='+str+'',
cache:false,
async: false,
success: function(data) {
// data is ur summary
$('.refresh').html(data);
return false;
}
});//end of ajax
});
</script>
<?php
while($obj = $c_content->fetch())
{
$title = $obj['lecture_title'];
echo '<article class="comment2">
//pdf link
<div class="comment2-body">
<div class="text" style="color:#999;padding-right:130px;">
<p><a href="../functions/pdfreader.php?'.$title.'""
style="color:#999" id="nextpdf">'.$title.'</a></p>
</div>
</div>
</article>
';
}
?>
</html>
pdfreader.php
//detect iframe pdf scroll
<script type="text/javascript">
$("myiframe").load(function () {
var iframe = $("myiframe").contents();
$(iframe).scroll(function () {
alert('scrolling...');
});
});
</script>
<?php
........
while($obj = $gettrend->fetch())
{
$coursefile = $obj['lecture_content'];
//this is my iframe
echo '<div class="mov_pdf_frame"><iframe id="myiframe"
src="https://localhost/einstower/e-learn/courses/pdf/'.$coursefile.'"
id="pdf_content"
width="700px" height="800px" type="application/pdf">
</iframe></div>';
}
?>
这里的主要问题是当我滚动 pdf 文档时没有任何反应,我如何检测滚动?
我发现这个小提琴有效,但我无法查看 javascript 解决方案。 http://fiddle.jshell.net/czw8pbvj/1/
【问题讨论】:
-
可能相关:stackoverflow.com/q/43264078/1531971(如果不是,可能是 edit 问题解释为什么不。)
-
没有接受该问题的答案,我也尝试了投票最多的解决方案,但没有成功。
-
“它不起作用” 也许分享这意味着什么?假设没有人知道你想要做什么。
-
什么都没发生,我检查了 Web 控制台但没有错误
-
另外:stackoverflow.com/q/33154598/1531971 或 stackoverflow.com/q/36193354/1531971 基本上,您将不得不通过展示您的研究来提供帮助;这就是它的工作原理。有人将不得不对回答感兴趣,这部分依赖于了解已经完成的基础工作。我们需要了解您的案例是什么导致这些解决方案不适合您。
标签: javascript php jquery html iframe