View real HTML source of a page

All browsers support “View page source” feature. But what it displays is source of the page as it was originally rendered by the server. In today’s Web 2.0 world page content can change a thousand times after that. Client-side script, user input, AJAX calls can contribute to page update.

But one line of JavaScript code can show you a real up-to date page source. Type following in your browser address bar:

javascript:void prompt('HTML Source',document.documentElement.innerHTML)

You will see a JavaScript prompt, with text field prefilled with HTML source of the page.

Just copy it from there and paste it to where it can be put to a good use.

Note “void” in front of function call. It prevents browser from going to a new page, displaying “null” after the prompt is closed.

This approach works both i IE and Firefox, but if you use IE, you can use “.outerHTML” property to display full page source in its entirety from <HTML> to </HTML>.

Leave a Reply

Your email address will not be published. Required fields are marked *