Created
January 1, 2019 20:00
-
-
Save jsanta/596541b4b289e48584aab8519a1585e8 to your computer and use it in GitHub Desktop.
PWA (essentially it applies to most cases) script for iOS and navigation mode detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
//... | |
// Detects if device is on iOS | |
const isIos = () => { | |
const userAgent = window.navigator.userAgent.toLowerCase(); | |
return /iphone|ipad|ipod/.test( userAgent ); | |
} | |
// Detects if device is in standalone mode | |
const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone); | |
// Checks if should display install popup notification: | |
if (isIos() && !isInStandaloneMode()) { | |
// do something | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment