The question How do I get the entire page's HTML with jQuery? might look similar, which helps in obtaining data from <html>
and <!DOCTYPE>
. But in addition, I also require to obtain any comments that persist before the <html>
tag.
I am displaying the page with the help of srcdoc attribute using jQuery. My current code to obtain the data is
$("#myiframe").contents().find('html')[0].outerHTML;
and a snippet in this answer to obtain <!DOCTYPE html>
Sample use case:
<!--
This comment will be used for further processing
-->
<!DOCTYPE html>
<html lang='en'>
<head>
...
</head>
<body>
...
</body>
</html>
<!--
This comment will be used for further processing
-->
The current output is only from <!DOCTYPE html>
to </html>
. Expected to have the comments outside.