Detect if page is viewed in samsung stock browser or as a standalone web app

久未见 提交于 2019-12-11 01:53:56

问题


As the title states, I’m trying to detect if my web page is being viewed as a web page in samsungs stock browser or if it is opened as a standalone web app saved on the homescreen. But the javascript-codes i’ve found for doing that only works for Safari and Chrome as far as I can tell.

Can someone please provide me with a good solution for this?


回答1:


For some reason, window.matchMedia('(display-mode: standalone)').matches is false on a PWA installed by Samsung Internet, even if its display mode is indeed standalone.

However, you can follow the method provided in this answer, which works on Samsung Internet:

Set the start URL in the manifest file to include a query string parameter, ex:

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

Then in your JavaScript you are able to check for this query string parameter.

Provided you are in standalone mode, the address bar is not visible to the user, so it would not affect them.



来源:https://stackoverflow.com/questions/53019733/detect-if-page-is-viewed-in-samsung-stock-browser-or-as-a-standalone-web-app

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