我正在将内容从一个框架复制到另一个框架。我的代码在 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/