view-source

Programmatically open “View Source” HTML Window in Browser with Javascript?

泄露秘密 提交于 2019-11-26 21:17:42
问题 How do I programmatically open the "View Source" window (using some Javascript) like when I right click in the browser and click "View Source"? Is this possible? 回答1: You could use this script, we simply grab the innerHTML of the html tag, reappend that, and paste that in a popup. function showSource(){; var source = "<html>"; source += document.getElementsByTagName('html')[0].innerHTML; source += "</html>"; //now we need to escape the html special chars, javascript has escape //but this does