iPhone WebApps, is there a way to detect how it wa

2019-01-10 06:01发布

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?

8条回答
Juvenile、少年°
2楼-- · 2019-01-10 06:35

Can be simplified to var webApp = window.navigator.standalone || false;

Can be simplified again to var webApp = window.navigator.standalone;

查看更多
戒情不戒烟
3楼-- · 2019-01-10 06:49

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!

查看更多
登录 后发表回答