Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone WebApps, is there a way to detect how it was loaded? Home Screen vs Safari?

I have an iPhone Web App, and I'm interested in detecting if the app was loaded either from:

  1. iPhone Safari
  2. iPhone installed web app (via the add to my home screen) which loads without the safari bars.

Any ideas?

like image 425
AnApprentice Avatar asked Apr 29 '10 15:04

AnApprentice


People also ask

Why did Apple change the layout of Safari?

Why did Apple redesign Safari? Apple said they are bringing important controls closer to your fingers with a bottom-oriented appearance. That means the address bar is now easier to access with one hand, especially if you have a larger iPhone like an iPhone 13 Pro Max.

Do iOS apps use Safari?

Now supported in iOS 15 and iPadOS 15, Safari web extensions are available on all Apple devices that support Safari. These extensions are built with Xcode and can communicate and share data with native apps — so you can integrate app content into Safari or send web data back to your app to create a unified experience.

How do you make websites appear as apps on iPhone?

In the browser, tap the Share button on a webpage, hit "Add to Home Screen," then select "Add." That gives you a home screen icon that looks just like other app icons but is merely a shortcut to the webpage chosen.


2 Answers

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

if (window.navigator.standalone) {     // fullscreen mode  } 
like image 85
Sharjeel Aziz Avatar answered Oct 11 '22 13:10

Sharjeel Aziz


You can detect the mode via Javascript as described above - or you can use PHP and the user agent.

<? if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"iphone")) {    if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"safari")) {       echo('Running in browser on iPhone');    }else{       echo('Running as stand alone WebApp on iPhone');    } }else{    echo('Running on device other than iPhone.'); } ?> 

Enjoy!

like image 23
cstrat Avatar answered Oct 11 '22 12:10

cstrat