Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get WHOLE content of iframe?

I need to get whole content of iframe from the same domain. Whole content means that I want everything starting from <html> (including), not only <body> content. Content is modified after load, so I can't get it once again from server.

like image 915
jesper Avatar asked Jan 01 '11 18:01

jesper


People also ask

How do I make an iframe occupy the whole page?

Next, we put the <iframe> inside this box, making it fill the whole box. To size the <iframe> , we ignore the width="560" height="315" element properties, and instead use the CSS properties width:100%;height:100%; . That's it: a full-width <iframe> with fixed aspect ratio. Enjoy.

Can javascript access iframe content?

You could use . contents() method of jQuery. The . contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.


1 Answers

I belive I've found the best solution:

var document = iframeObject.contentDocument;
var serializer = new XMLSerializer();
var content = serializer.serializeToString(document);

In content we have full iframe content, including DOCTYPE element, which was missing in previous solutions. And in addition this code is very short and clean.

like image 173
jesper Avatar answered Sep 28 '22 05:09

jesper