我想显示加载图标,直到pdf加载到网页中。我已经粘贴了我尝试过的内容,但加载图标一直显示,即使pdf已经完全加载。所以,我得出结论,$iFrame.load(function()
不会触发任何事情。从JSFiddle得到这个代码。但在JSFiddle,它正在发挥作用。
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<style>
iframe {
width: 100%;
height: 100%;
border: 5px solid green;
}
</style>
<script>
$(function(){
var $iFrame = $('iframe');
$iFrame.load(function(){
$('h3').html('PDF Loaded!');
});
$('h3').html('Loading PDF...');
$iFrame.attr('src', 'http://listic.ru/jQuery_Cookbook.pdf');
});
</script>
</head>
<body>
<h3></h3>
<iframe></iframe>
</body>
</html>
我需要对缓存文件进行额外的检查(谁触发了该事件,就在添加侦听该事件的事件处理程序之前)。我尝试了下面的jquery,结果很好。
$iFrame.on('load', function() {
$('h3').html('PDF loaded...');
}).each(function() {
if(this.complete) $(this).load();
});