Skip to content

Instantly share code, notes, and snippets.

@jsanta
Created January 1, 2019 20:00
Show Gist options
  • Save jsanta/596541b4b289e48584aab8519a1585e8 to your computer and use it in GitHub Desktop.
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
<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