how to get fully computed HTML (instead of source HTML)?

烂漫一生 提交于 2019-11-28 17:13:36

With Firebug's HTML tab, you can right click on the <html> element, and click "Copy HTML".

You can do the same thing with Developer Tools in Chrome/Safari.

The Web Developer Toolbar for Firefox has a "View Generated Source" option which provides this functionality.

with (window.open("")) {
    document.open("text/html");
    document.write("<!--\n"); //for live version delete this line
    document.write(opener.document.documentElement.outerHTML.replace(/</g,"<").replace(/>/g, ">"));
    document.write("\n//-->"); //for live version delete this line
    document.close();
    document.title = "DOM Snapshot:" + opener.document.title;
    focus();
}
  1. Open console
  2. copy paste the above code and execute
  3. it opens an empty page,
  4. now inspect the page with right click or f12,
  5. copy outerhtml of the comment
  6. paste wherever you want
  7. optionally remove the comment at the start and end

If you want a live version that is clickable, then simple leave out the comment tags in the above code.

It is not possible generally. Here is excerpt from my bookmarklet which relies on non-standard outerHTML:

with (window.open("")) {
    document.open("text/html");
    document.write("<PRE>");
    document.write(opener.document.documentElement.outerHTML.replace(/</g,"<").replace(/>/g, ">"));
    document.write("</PRE>");
    document.close();
    document.title = "DOM Snapshot:" + opener.document.title;
    focus();
}

Note: DTD is missing and not retrievable at all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!