iPhone App Mode Bookmarklet

If you're an iPhone (or iDevice) user you probably have a lot of applications on your phone. In fact, if you're a typical iPhone user, you probably have way too many applications on your phone. Happy to encourage your app addiction, many popular websites like Facebook and Wolfram Alpha offer native applications through the iPhone App Store. However, others like Gmail and Google Voice are only available as web applications. For full featured web applications like these, Apple offers the option to run in "App Mode" through the use of a few tags added to the html head.

<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="apple-touch-startup-image" href="startup-image.png" />

These tags tell your iPhone to save the webpage as a special type of home screen bookmark. The site will launch with a specified startup image and without the Safari UI, much like a native application. When the iPhone first came out, I assumed it was only a matter of time before sites like Gmail started using these tags to run like native apps when launched from the home screen.

However, websites running in app mode don't remember their state on close (Even with the introduction of multitasking in 4.0). That by itself isn't so bad, but in addition, links external to the website will launch in Safari. This means if a user clicks any external link they will have to start over at the home page when returning from Safari. That's a pretty bad user experience, so websites don't tend to utilize app mode unless they are truly self contained. This is why Apple leaves the choice of whether to run a website in app mode up to the site owner.

I, on the other hand, like to live dangerously. I also don't tend to add websites to my home screen unless I want to run them like applications. If I wanted to bookmark a site I would have just bookmarked it. If I want to load up Gmail as if it were a native application, I should be able to; risks be damned. Therefore...

Activate App Mode

Simply add the above bookmarket to Safari's bookmarks, attach your iPhone to your computer, and sync your bookmarks with your phone. The bookmarklet should then be available on your phone and ready to use. At least, this is the way I've been told to do it on every single site I've seen which offers an iPhone bookmarklet.

Personally, I have neither the time nor the inclination for a method which requires me to use Safari, set up bookmark syncing, and dig my iPhone cable out from under my bed. If the syncing method works for you, great, but I have an alternative method in case you'd like to forgo any mattress excavation.

  1. Load this blog post in Safari on your iPhone.
  2. Press and hold on the following code box to select all the text inside.
  3. javascript:(function(){var a=document.getElementsByTagName('head').item(0);if(document.querySelectorAll('meta[name=apple-mobile-web-app-capable]').length==0){var c=document.createElement('meta');c.name='apple-mobile-web-app-capable';c.content='yes';a.appendChild(c)}if(document.querySelectorAll('link[rel=apple-touch-startup-image]').length==0){var b=document.createElement('link');b.r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8LCL79mWsAAAAASUVORK5CYII=';a.appendChild(b)}alert('App Mode Activated')})();
  4. Press the "Copy" bubble that pops up.
  5. Press the "+" icon on the bottom toolbar of Safari and choose "Add Bookmark" (Yes, it will bookmark this page).
  6. Name the bookmark "Activate App Mode" and save it.
  7. Open your bookmarks using the book icon on the bottom toolbar of Safari.
  8. Click the "Edit" button at the bottom of the bookmarks screen and choose the bookmark you just created.
  9. Tap the url field and delete the current url.
  10. Tap and paste the bookmarklet text into the url field.
  11. Save your new bookmarklet.

Voila! Much less painful than syncing with Safari, and it doesn't require me to hunker down under the bed. Now, when you want to save a website to your home screen that will launch in app mode, simply follow this procedure:

  1. Open up your bookmarks and choose the "Activate App Mode" bookmarklet.
  2. After a slight pause, a dialogue will pop up informing you app mode has been activated.
  3. Press the "+" button at the bottom of Safari and choose "Add to Home Screen."

And that's it! Your newly created web app will open faster than if you were loading it in Safari and comes with a basic loading screen. Keep in mind that external links will still open in Safari, closing your application, so app mode may not be appropriate for all sites. In fact, it's probably not appropriate for most sites, but it's nice to have as an option.

How Does It Work?

If you're the technical type, here's the skinny on the guts of the bookmarklet.

It turns out Safari only checks for the existence of the afore mentioned meta and link tags when the home screen application is created, not every time the site is loaded. The bookmarklet adds these tags if necessary so the website will be saved with the instructions to run in app mode on launch. A base64 encoded image is used for the startup image instead of an external href in order to keep the bookmarklet completely self contained.

If you'd like, you can replace BASE64DATAGOESHERE in the code below with your own custom image data and create your own custom bookmarklet. Your startup image must be 320x460 pixels, as specified in the Safari Reference Library, but that seems to be the only restriction. Unfortunately animated images are not supported, so loading spinners are out (believe me, I tried). Once you've created your image, use this online converter to turn it into a base64 string.

javascript:(function(){

  var head = document.getElementsByTagName('head').item(0);

  if(document.querySelectorAll('meta[name=apple-mobile-web-app-capable]').length == 0){
    var meta = document.createElement('meta');
    meta.name = 'apple-mobile-web-app-capable';
    meta.content = 'yes';
    head.appendChild(meta);
  }

  if(document.querySelectorAll('link[rel=apple-touch-startup-image]').length == 0){
    var link = document.createElement('link');
    link.rel = 'apple-touch-startup-image';
    link.href = 'data:image/png;base64,BASE64DATAGOESHERE';
    head.appendChild(link);
  }

  alert('App Mode Activated');

})();

Comments

This is exactly what I have been looking for!

Thank!

This is F-ing awesome!!!!

This works great on the iPhone, and I have been able to add my very own splash page etc when the graphic was converted to a png first, before encoding to base64. Is it possible to have the splash page graphic show on the IPad? The same JavaScript code does not appear to work on the iPad currently? Any ideas?

Awesome so far...

Hm, that's odd. I would expect it to work the same way on the iPad. I don't have the updated iOS SDK with the iPad emulator on this computer, but I'll try to take a look at home this weekend and see if I can figure anything out.

Thanks. Yes, please take a look on the iPad. The splash page graphic does not show unfortunately.

Also, is it possible to embed the APP icon graphic itself as base64 into your JavaScript? The reason I ask, is that my website/s are generated by a proxy based parser/servlet, and as a general public user, I cannot edit that servlet to reference the icon graphic url (ie cannot add the necessary custom header code to call on the icon graphic).

Any possible suggestions as to how I can get an app icon graphic?

Thanks for a great tool.

i am having hard time in activating bookmarklet safari mode steps u added on app advice article please help i hav iphone 3gs i followed steps but i dont see anything different

Works great, thanks.

Wow. I just found this, and this is EXACTLY what I have been looking for! Thank you SO much!

This works great on the iPhone, and I have been able to add my very own splash page etc when the graphic was converted to a png first, before encoding to base64. Is it possible to have the splash page graphic show on the IPad? The same JavaScript code does not appear to work on the iPad currently? Any ideas?hopkonlin htr xorfgwogk gr kawhenree jd xisolamei

I am only writing to let you know of the extraordinary experience my friend's princess gained reading through your web site. She learned such a lot of things, including how it is like to possess a very effective teaching mood to get folks very easily know specific multifaceted matters. You undoubtedly exceeded my expectations. Thank you for supplying these effective, trusted, explanatory and as well as fun tips about this topic to Sandra.
memory foam mattress topper

Search Marketing - Search Marketing solutions to UK businesses looking to promote their websites on the internet and through the search engines.

counter surveillance equipment - Spy Equipment UK, providers of quality spy equipment, Phone and Video Surveillance.

I usually get iPhone apps on the Apple store at a price that is not cheap. I will try to incorporate this application into my phone, I hope to operate properly, because I really need an email application, google and facebook on my phone. Tools.com - Shop for great deals on power tools, hand tools, air compressors, generators , tool storage and ladders.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may embed videos from the following providers google, vimeo, youtube. Just add the video URL to your textarea in the place where you would like the video to appear, i.e. http://www.youtube.com/watch?v=pw0jmvdh.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <h2> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <br> <p> <img><object><embed>

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Search Archives

Recent Tweets