Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting HTMLDocument to a printable string

Tags:

javascript

dom

I want to convert a Javascript DOM HTMLDcument to a string that I can write to a file. But how do you do the string conversion of the HTMLDocument to xml?!

Update If possible I'd like to see the html that is generated once any dynamic javascript rendering has been applied.

like image 809
Joel Avatar asked Dec 10 '22 18:12

Joel


2 Answers

The DOM way of converting HTMLDocument object to XML is:

new XMLSerializer().serializeToString(oDocument);

In Internet Explorer there is no way to get proper XML representation of HTML document object by any built-in means. There you would need to implement serialization mechanism yourself - traversing the DOM tree and creating XML string.

like image 127
Sergey Ilinsky Avatar answered Dec 27 '22 19:12

Sergey Ilinsky


'<html>'+document.documentElement.innerHTML+'</html>'
like image 42
Joel Avatar answered Dec 27 '22 19:12

Joel