【问题标题】:Load event not firing in iframe while loading pdf in iframe在 iframe 中加载 pdf 时,加载事件未在 iframe 中触发
【发布时间】:2015-05-20 19:32:32
【问题描述】:

这是我的 HTML :-

<iframe src="Dyanamicallygeneratedpath" id="iPrintform" name="iPrintform"  class="iframeDisable" scrolling="auto" height="600" width="650" style="display:block;"></iframe>

jQuery :-

第一次尝试:-

var iFrame = $('#iPrintform');
iFrame.bind('load', function () { //binds the event
alert('iFrame Reloaded');
});

第二次尝试:-

$("#iPrintform").on("load", function () {
alert("Iframe loaded");
});

我尝试将加载事件、onready 事件绑定到 iframe,chrome 没有任何效果。

【问题讨论】:

  • 尝试使用 live 代替 bind
  • Live 也不行。

标签: javascript jquery google-chrome iframe onload-event


【解决方案1】:

尝试实现以下代码。

var iframeID = $('#iPrintform').contents();
    iframeID.find("addevents").click(function(){
       alert("working");
    });

【讨论】:

    【解决方案2】:

    等到 iframe 加载完毕,然后通过 iframe 的 contentWindow.document 进行绑定

     var xiframe = $('iframe')[0];
     iframe.onload = function(){
       // log("iframe loaded");
       $(xiframe.contentWindow.document)
        .bind(function(){ ... });
        $(xiframe.contentWindow.body).addClass('..');
        };
    

    【讨论】:

    • 不走运!事件未绑定到 iframe。
    猜你喜欢
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    相关资源
    最近更新 更多