Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell if WebApp launched via URL or link on iPhone home screen

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.

like image 298
James Avatar asked Sep 26 '09 15:09

James


People also ask

How do I add a link to my iPhone Home Screen?

You can add shortcuts to the Home Screen, and optionally group them into folders. In the Shortcuts app on your iOS or iPadOS device, tap on a shortcut, then tap to open Details. Tap Add to Home Screen.

How do I save a website as a app on my iPhone?

At the bottom of the Safari browser, find and tap on the share icon on the menu bar – it looks like a box with an up arrow. From the list of share options, choose Add to Home Screen. An app-looking icon will pre-populate. Give it a name that is recognizable to you.


2 Answers

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.

like image 141
GeoNomad Avatar answered Oct 10 '22 04:10

GeoNomad


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)

like image 38
rpetrich Avatar answered Oct 10 '22 06:10

rpetrich