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

Jquery Iframe onload event is not executing on Google chrome

本文关键字:Google chrome 执行 Iframe onload 事件 Jquery      更新时间:2023-09-26

我正在将内容从一帧复制到另一帧。我的代码在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注入DOM:之前添加加载侦听器

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