I'开发者_StackOverflowm trying to get page source together with doctype, head and body.
window.content.document is document but I can't collect anything except innerHTML which does not include doctype.
DOCTYPE isn't included because it isn't a child of the document element, it's rather a direct child of the document itself. You can serialize the entire document using XML serializer however:
var serializer = new XMLSerializer();
alert(serializer.serializeToString(window.content.document));
This will do an XML serialization - not quite the same thing as HTML. If that's a problem you can go through the window.content.document.childNodes
collection and get node.innerHTML
for the element nodes (node.nodeType == 1
), only use XMLSerializer
on the rest of them. See https://developer.mozilla.org/en/XMLSerializer for more info.
精彩评论