Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Iframe onload event is not executing on Google chrome

I am copying the content from one frame to the other. My codes are working in Mozilla Firefox but it is not working in Google Chrome. Can someone tell me where I went wrong?

This part is not executing in Google chrome :

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

});


Below is my code block:

$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);
});
like image 696
madi Avatar asked Aug 17 '13 08:08

madi


1 Answers

It appears as if load-event fires too quick, add the load-listener before you inject the iframe into the DOM:

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

  }).appendTo(uxcontainerPath);
like image 100
Dr.Molle Avatar answered Oct 18 '22 04:10

Dr.Molle