javascript - Jquery Iframe onload 事件未在 Google chrome 上执行

标签 javascript jquery iframe

我正在将内容从一个框架复制到另一个框架。我的代码在 Mozilla Firefox 中有效,但在 Google Chrome 中无效。谁能告诉我哪里出错了?

此部分未在 Google chrome 中执行:

$('#frame1').load(function(e){  

});


下面是我的代码块:

$headContent = $("#mainframe").contents().find("head").html();
$bodyContent = $("#mainframe").contents().find("body").html();

$('<iframe />');  
$('<iframe />',{ id: 'frame1',
                 class:'myframe',
                 height: 600,
                 width: "100%"
}).appendTo(uxcontainerPath);


$('#frame1').load(function(e){  
    console.log("Executed #frame1 load"); //this console line is not executed in chrome           
    $(this).contents().find('html').append('<head></head>');
    $(this).contents().find('head').append($headContent);
    $(this).contents().find('body').append($bodyContent);
});

最佳答案

加载事件似乎触发得太快了,在将 iframe 注入(inject) DOM 之前添加加载监听器:

  $('<iframe />',{ id: 'frame1',
                 class:'myframe',
                 height: 600,
                 width: "100%"
  }).load(function(e){  
    console.log("Executed #frame1 load");          

  }).appendTo(uxcontainerPath);

关于javascript - Jquery Iframe onload 事件未在 Google chrome 上执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18286981/

相关文章:

javascript - 无法使用 Cheerio 获取 iframe

javascript - 如何在 chrome 中禁用 iframe 的滚动

javascript - 知道 JavaScript 中表单的名称

javascript - 使用 JavaScript 查找文本的边界

javascript - 如何检查用户是否已登录 javascript

javascript - 我们可以在二维码中保存/存储多少数据/信息?

jquery - 仅从一个链接中删除 colorbox(jQuery 插件)功能,然后重新应用它

javascript - jQuery $.extend 不覆盖目标属性

javascript - 在 Firefox 中注销后无法关闭选项卡

html - 如果在 &lt;iframe&gt; 中单击链接,HTTP Referer 是什么?