5

我正在将内容从一帧复制到另一帧。我的代码在 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);
});
4

1 回答 1

8

看起来好像加载事件触发得太快了,在将 iframe 注入 DOM 之前添加加载侦听器:

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

  }).appendTo(uxcontainerPath);
于 2013-08-17T09:34:10.387 回答