Created
January 1, 2019 20:07
-
-
Save jsanta/b11741a03137205b0ee9a26796ee030d to your computer and use it in GitHub Desktop.
iOS and navigation mode detection script
This file contains hidden or 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> | |
| //... | |
| function showIosInstall() { | |
| let iosPrompt = document.querySelector(".ios-prompt"); | |
| iosPrompt.style.display = "block"; | |
| iosPrompt.addEventListener("click", () => { | |
| iosPrompt.style.display = "none"; | |
| }); | |
| } | |
| // 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()) { | |
| showIosInstall(); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment