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

load-event の起動が速すぎるように見えます。iframe を DOM に挿入する前に load-listener を追加してください。

  $('<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 に答える