How to detect that the application is being visited through a homescreen bookmark (embedded)?

杀马特。学长 韩版系。学妹 提交于 2020-02-05 04:01:09

问题


I am writing a react native application with expo SDK36.

When a user visit the website, the manifest is used with splash and favicon to produce a nice PWA.

If I add a bookmark on my home screen with safari or chrome, I get my application available without any store installation and without the search bar from the browser.

How can I detect that the app is running in an embedded webview ?


回答1:


You can detect whether your web app is running in browser or as standalone using display mode.

If you want to detect the display mode for styling purpose then read here.

Alternatively, you can detect display mode via javascript as below.

  if (window.matchMedia('(display-mode: standalone)').matches) {
                 console.log("This is running as standalone.");
     }

Another simple way is you can append a query string to your start url to detect if, PWA is running.

  "start_url": "./?mode=standalone"


来源:https://stackoverflow.com/questions/59622565/how-to-detect-that-the-application-is-being-visited-through-a-homescreen-bookmar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!