Yes, you can.
While technically a page open in Chrome browser tab can't directly check whether a home screen shortcut exists, the page's local data (localStorage
, IndexedDB) is shared between home screen instance and browser tabs, so this can be used to communicate the existence of the home screen version.
- Detect if the app is running from home screen
- If it's ran from home screen, save this fact to
localStorage
- Profit! (by reading this from
localStorage
in any tab)
When the app is in standalone view (which is possible only when launched from home screen), the CSS media query (display-mode: standalone)
will match. In Javascript you can read it using:
matchMedia('(display-mode: standalone)').matches
(BTW: the non-standard iOS equivalent of this is navigator.standalone
, but iOS doesn't share state between home screen and Safari, so you're out of luck there).
However, instead of custom instructions I suggest meeting Chrome's criteria for "progressive web app" and let Chrome do the prompting for you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…