1

Is there any way to copy iframe's content into popup window in jQuery?

$(popUpWindow.document).append($('#iframe1').contents());
$(popUpWindow.document).append($('#iframe1').contents().find('body').html()); 

All of them are not working!

Thanks

Thurein
  • 2,536
  • 7
  • 34
  • 49
  • 1
    Is the iFrame pointing to a page on the same domain? You may be running in to cross-domain security. Also, if you're going for the whole page, what's wrong with popup.location = iframe.location? – Brad Christie Mar 30 '11 at 18:59
  • @Bard ... In fact, iFrame is not pointing to any external page, it is just a hidden iFrame where we normally store a html page. – Thurein Mar 30 '11 at 19:01
  • You may find this answer on [copying the dom to a new window](http://stackoverflow.com/questions/2155122/copy-current-webpage-into-a-new-window) helpful. – NT3RP Mar 31 '11 at 01:41
  • @Nicholas ... in fact, my trouble is getting the content from iFrame – Thurein Mar 31 '11 at 02:47
  • it might be easier to have the html content inside a hidden
    instead of an iframe.
    – CarlosZ Mar 31 '11 at 03:00

2 Answers2

0

Please mention which popup you are using and by content what do you mean.

Example for jquery-ui popup (dialog)

HTML:

<div id="myDialog" >
  <p>default dialog</p>
</div>

jQuery:

$(function() {
    $( "#myDialog" ).dialog();
    $( "#myDialog p" ).html($("iframe").contents().find("body").html());
}); 
eldarerathis
  • 35,455
  • 10
  • 90
  • 93
Manoj
  • 73
  • 3
0

If all that you need to do is actually obtain the iframe contents, you can try something a bit more low level than jquery: raw javascript!

var getIframeContent = function (id) {
    var iframe = document.getElementById(id);
    return iframe.contentWindow.document.body.innerHTML;
}

But I would imagine something similar is going on underneath the hood in JQuery.

NT3RP
  • 15,262
  • 9
  • 61
  • 97