问题
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