View Source of a web page on iPad, iPhone or iPod Touch (using mobile Safari)

After recently implementing WPTouch Pro for mobile devices, I was curious to know what HTML it generated when viewed from my iPhone and iPad. Surprisingly the mobile Safari browser does not have an option to view source, even more surprising is that I’ve just found this out after owning a iPhone for over 3 years!. This little guide shows you how to view the source code for the HTML, CSS and JavaScript code of a web page from Safari on the iPad, iPhone or iPod touch.

This simple bookmarklet is a piece of JavaScript code saved as a bookmark. When you want to see the source of a web page, just click the bookmark and the source of the page is displayed.

    var w ='about:blank'),
        s = w.document;
    var f = s.body.appendChild(s.createElement('form'));
    var i = f.appendChild(s.createElement('input'));

View Source (click to try)

Step 1.

Visit this page using Safari on your iPad, iPhone or iPod touch.

Step 2.

Tap the Share button and select Add Bookmark from the popup menu.

Step 3.

In the title field, enter View Source. Leave the address field as is for now, and tap save.

Step 4.

Using your touch selection skills, copy the following JavaScript code to the devices clipboard (this is a condensed version of the code above)

javascript:(function(){var"about:blank"),a=d.document;a.write("<!DOCTYPE html><html><head><title>Loading Source</title></head><body></body></html>");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()})()

Step 5.

Tap the Bookmarks icon and then edit. Find the View Source bookmark in the list and tap the right arrow to get the bookmark details. Now tap on the address field and hit the X icon to clear the existing entry. Tap and paste the JavaScript code from the clipboard (Step 4).

Step 6.

Tap the Bookmarks navigation item to save the changes.

All Done.

Simply visit any web page, and if you want to see it’s source code, tap on the Bookmarks icon and select the View Source bookmark.

Note that the source shown is the generated DOM, and not the original HTML. These might differ depending on the amount of JavaScript used on the page.

Alternative View Source code

You could use this code for the bookmarklet instead, described by , which is “pure” but doesn’t include the highlighted syntax, clickable links or selectable text.

    var w ='about:blank'),
        s = w.document;
    s.write('<!DOCTYPE html><html><head><title>Source of ' + location.href + '</title><meta name="viewport" content="width=device-width" /></head><body></body></html>');

    var pre = s.body.appendChild(s.createElement("pre")); = 'auto'; = 'pre-wrap';

Copy & Paste the following for the alternative View Source code:

View Source (click to try)


  1. If I needed evidence that tablet computers are media consumption toys, this is it.

    A good idea – well done – but nobody doing serious work on an iDevice, etc., could contemplate these sort of botches and workarounds for anything but the shortest / most trivial tasks. Another example of why I find myself saving actual work to do on an actual computer, rather than a tiny piece of glass which I can dab with my fingers, halving the already small screen space whilst I do so.

    Media consumption: tablets great.
    Actual work: tablets rubbish.

  2. I would love to try this but I can not select anything on your page – not the code, not even the text outside the box with the code in it. And yup, I know how to copy and paste on my iPad. Surely I am missing something pretty simple?!

  3. It works! Even an extreme non-techie like me figured it out after a couple attempts. Thank you!
    A Reader: No one cares what you think. :)

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>