45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
|
|
// Helps you detect mobile browsers (to show a relevant message as the process of installing your PWA changes from browser to browser)
|
||
|
|
function isAndroid() {
|
||
|
|
return navigator.userAgent.match(/Android/i);
|
||
|
|
}
|
||
|
|
function isBlackBerry() {
|
||
|
|
return navigator.userAgent.match(/BlackBerry/i);
|
||
|
|
}
|
||
|
|
function isiOS() {
|
||
|
|
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||
|
|
}
|
||
|
|
function isOpera() {
|
||
|
|
return navigator.userAgent.match(/Opera Mini/i);
|
||
|
|
}
|
||
|
|
function isSamsung() {
|
||
|
|
return navigator.userAgent.match(
|
||
|
|
/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
function isWindows() {
|
||
|
|
return (
|
||
|
|
navigator.userAgent.match(/IEMobile/i) ||
|
||
|
|
navigator.userAgent.match(/WPDesktop/i)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
function isMobile() {
|
||
|
|
return (
|
||
|
|
this.isAndroid() ||
|
||
|
|
this.isBlackBerry() ||
|
||
|
|
this.isiOS() ||
|
||
|
|
this.isOpera() ||
|
||
|
|
this.isSamsung() ||
|
||
|
|
this.isWindows()
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Use this to check if the user is already using your PWA - no need to prompt if in standalone
|
||
|
|
function isStandalone() {
|
||
|
|
const isStandalone = window.matchMedia("(display-mode: standalone)").matches;
|
||
|
|
if (document.referrer.startsWith("android-app://")) {
|
||
|
|
return true; // Trusted web app
|
||
|
|
} else if ("standalone" in navigator || isStandalone) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|