I have an iPhone Web App, and I'm interested in detecting if the app was loaded either from:
- iPhone Safari
- iPhone installed web app (via the add to my home screen) which loads without the safari bars.
Any ideas?
I have an iPhone Web App, and I'm interested in detecting if the app was loaded either from:
Any ideas?
I prefer this one-liner to determine whether it's fullscreen/in a web app or not.
You can determine whether a webpage is displayed in full-screen mode using the window.navigator.standalone read-only Boolean JavaScript property. https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html
This is what I use, works great:
How to do it with PHP and filter false positives
I think that @strat 's answer is in the right direction, if you want to use PHP. Except that it won't work unless the mobile app capable meta is set. Otherwise the iPhone will place in home a bookmark opening mobile safari. Also, it returned false positives, for example when accessing the page from any other browser on iPhone, like the Facebook browser.
Luckily, the standalone user agent string has a particularity: it only has 3 slashes in it. I tested various other browsers and they all have more than 3. It's hackish, but we can use this at our advantage. Also, it's interesting to note that a standard webview in a app will have 2 slashes.
So this is the minimum working example:
Check the HTTP-Headers when accessing the site from iPhone Safari and the WebApp to see if they are different.
I don't know if they are, but if they are, I'm sure you'll be able to implement that somewhere in your website.
http://php.net/manual/en/function.headers-list.php
I'm not sure how far back this behavior goes, but iOS will present different UserAgent strings to the server which can be used to detect if the page is being requested by a webapp or safari browser.
Safari Browser
Home Screen Button/Web App
Notice it does not include 'Safari' in the UserAgent. I've confirmed that this behavior goes back to at least iOS 7, but I'd imagine even further.
So you can test for the presence of
iPhone
oriPad
in the UserAgent string and lack ofSafari
to detect that it's been opened from the Home screen.