Skip to content

Instantly share code, notes, and snippets.

@jsanta
Created January 1, 2019 20:07
Show Gist options
  • Select an option

  • Save jsanta/b11741a03137205b0ee9a26796ee030d to your computer and use it in GitHub Desktop.

Select an option

Save jsanta/b11741a03137205b0ee9a26796ee030d to your computer and use it in GitHub Desktop.
iOS and navigation mode detection script
<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