How to avoid safari alert when redirecting to iTunes link

I am using the following piece of code for launching my app from safari. What I want is, when a user clicks on the link from safari, it will launch my app, and If the app is not installed in device, safari will redirect to the iTunes link of that particular app.

   setTimeout(function() {
  window.location = "";
}, 25);

// If "custom-uri://" is registered the app will launch immediately and your
// timer won't fire. If it's not set, you'll get an ugly "Cannot Open Page"
// dialogue prior to the App Store application launching
window.location = "custom-uri://";

Everything is working fine, except safari showing an error alert before redirecting to the iTunes link (if the app is not installed in device).

  • How to capture iOS Safari event on text selection change within Javascript?
  • React-Native fetch, Network request failed. not using localhost
  • Force iOS iPhone youtube embed player out of fullscreen
  • Using javascript Open app in appstore/playstore if website is opened in mobile
  • How to Debug Javascript in IOS Action App Extension
  • How to model a button with icons in react-native
  • “Safari cannot open this page, because the address is invalid”.

    As it is a bad user experience, is there any way that I can suppress or avoid this popup before redirecting to the iTunes link.?

  • Get continuous scroll events in iOS Chrome
  • m3u8 + 404 + ios Safari = annoying popup: “The requested URL was not found on this server”
  • Link to open facebook app if app exists, else webpage
  • iOS 8 shows popup for basic auth on 401 for OAuth
  • Check for app Installed or not in iOS WITHOUT ALERT in safari
  • iOS 7.1 input field positioned below virtual keyboard forces zoom on focus
  • One Solution collect form web for “How to avoid safari alert when redirecting to iTunes link”

    You can open the app through iframe to suppress mobile safari “invalid address” warnings. This code works for me: