iframe或对象加载功能不起作用

时间:2015-02-18 07:00:06

标签: php jquery pdf

我想显示加载图标,直到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>

1 个答案:

答案 0 :(得分:0)

我需要对缓存文件进行额外的检查(在添加事件处理程序之前,已经触发了事件)。我尝试了以下jquery,它工作正常。

 $iFrame.on('load', function() {
  $('h3').html('PDF loaded...');
}).each(function() {
  if(this.complete) $(this).load();
});
相关问题