function openKongeparkenApp() { const appScheme = "kongeparken://"; // The custom protocol for the app const playStoreUrl = "https://play.google.com/store/apps/details?id=no.kongeparken.app"; const appStoreUrl = "https://apps.apple.com/no/app/kongeparken/id1114005168"; // Attempt to open the app window.location.href = appScheme; // Fallback logic: If the page is still visible after 2 seconds, // it likely means the app isn't installed. setTimeout(function() { if (document.hidden || document.webkitHidden) { return; // App opened successfully } // Redirect to the appropriate store based on User Agent const userAgent = navigator.userAgent || navigator.vendor || window.opera; if (/android/i.test(userAgent)) { window.location.href = playStoreUrl; } else if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { window.location.href = appStoreUrl; } }, 2000); }