Suppose you are browsing using the Safari web browser in your iPad or iPhone and you want to see the HTML source code of a website. Unfortunately, the Safari browser doesn't have an inbuilt option to view the source code and you would have to switch to your computer in order to see it.

Here's a cool trick that would allow you to view the source code of a website directly in your iPad or iPhone browser -

View source in iPad

Setting up The View Source Bookmark.

The trick here is to setup a bookmark that would run a small piece of javascript code which will extract and display the source code of the page for you.

  1. Open any website using their Safari browser on your iPhone or iPad. Then tap on the "Add Bookmark" button just next to the address bar. You can name the bookmark as "View Source" and save it.

    Add bookmark iPad

  2. Now tap on the bookmark button on the top left, click on edit and select the "View Source" bookmark we just created.

    Edit bookmark iPad

  3. Copy the below code and paste it in the URL field of the bookmark and tap on "Done".
    Edit bookmark in iPad

View Source code in iPhone and iPad.

Now when ever you want to see the source code of any website, just open it in Safari and tap on the "View Source" bookmark.

Source code of website in iPad

The above javascript code for the bookmark just shows you the source code without any formatting. If you would like to view the source code in a better way, use this code instead of the one above.

javascript:(function(){var"about:blank"),a=d.document;a.write("Loading Source");a.close();var b=a.body.appendChild(a.createElement("form"));b.setAttribute("method","post");b.setAttribute("action",""+location.href);var c=b.appendChild(a.createElement("input"));c.setAttribute("type","hidden");c.setAttribute("name","DOM");c.setAttribute("value",encodeURIComponent(document.documentElement.innerHTML));b.submit()})()

This one sends the URL to an external server for processing and shows you a color formatted version of the HTML source code.

Source code of website in iPad