How to get WHOLE content of iframe?

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.


If it is on the same domain, you can just use

iframe.contentWindow.document.documentElement.innerHTML

to get the content of the iframe, except for the <html> and </html> tag, where

iframe = document.getElementById('iframeid');