10
votes

Is there a way of telling whether my Web Application has been launched from a button on the user's iPhone home screen? I want to display a "add this WebApp to your home screen" prompt if the user has accessed the WebApp via safari by typing in a URL.

4
How do you make thhe link "add this webapp to your homescreen"? Thanks - Alec Jacobson

4 Answers

26
votes

window.navigator.standalone

True if you have launched from the Home Screen. False if in the Safari browser.

Documented here:

https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html

It works with OS 2.1 and up.

2
votes

In Safari, the scrollY will start at a negative value if inside Safari, and at 0 if running as an application.

Likely the viewport will change as well (if it does, this is a more reliable method)

1
votes

jQTouch detects this (try the demo). It's open source, so you should be able to find out how.

0
votes

If I remember correctly there's a thing in the server log that shows what the user's previous page was. So the only way I can think of is if the user was on a previous page display the "add" thing, and if they didn't don't