iOS9: Try to open app via scheme if possible, or redirect to app store otherwise

My question is about iOS9 only!

I have an HTML landing page, and I try to redirect the user to my app via URL scheme if the app is installed, or redirect to the Appstore otherwise.

My code is:

document.addEventListener("DOMContentLoaded", function(event) {

  var body = document.getElementsByTagName('body')[0];
  body.onclick = function () {

var timeout;

function preventPopup() {

    timeout = null;
    window.removeEventListener('pagehide', preventPopup);

function openApp(appInstanceId, platform) {

  window.addEventListener('pagehide', preventPopup);
  document.addEventListener('pagehide', preventPopup);

  // create iframe
  var iframe = document.createElement("iframe");
  iframe.setAttribute("style", "display:none;");
  iframe.src = 'myscheme://launch?var=val';

  var timeoutTime = 1000;
  timeout = setTimeout(function () {

    document.location = '';

  }, timeoutTime);

The problem is that the iframe trick doesn't work in Safari iOS9.

Any idea why?

My iframe trick based on this answer.



The iframe trick no longer works -- my guess is that Apple knows it will encourage more developers to implement Universal Links, more quickly.

You can still set window.location='your-uri-scheme://'; and fallback to the App Store after 500ms. There is a "dance" between popups if you take this approach, as we do at Branch (we do as a fallback if Universal Links don't work).

window.location = 'your-uri-scheme://'; // will result in error message if app not installed
setTimeout(function() {
   // Link to the App Store should go here -- only fires if deep link fails                
   window.location = "";
}, 500);

I wish I had a better answer for you. iOS 9 is definitely more limited.

For a helpful overview of what's needed for Universal Links should you go that route, check out my answer here or read this tutorial


As already mentioned setting window.location on iOS 9 still works. However, this brings up an Open in App dialog. I've put an example on that:

  1. Launches Twitter when the Open in Twitter app is clicked.
  2. Falls back to the Twitter app in the App Store.
  3. Redirects to Twitter or the App Store without the user selecting Open in the Open in App dialog.
  4. Works in all browsers on iOS and Android.

Look at the source of for more information.


Maybe try giving you app support to Universal Links

Idea: Avoid custom (JavaScript, iframe) solutions in Safari, replace you code with a supported Universal Link.


    <div class"app-banner-style">
        <a href="">In app open</a> 

if you app support Universal Links (e.g., you muss configure your domain (and path) and iOS9 should be react to it link opening you App. That is only theory, but I guess should be work :)


iframe hack doesn't work in ios9 anymore. Possible solution is use two buttons. Example:

$('#goToStoreBtn').text( "go to store" ).click(function(event){
    window.location = storeUrl; //

$('#goToAppBtn').text( "go to app" ).click(function(event){
    window.location = appUrl;  // myApp://...

This is relatively old thread, but I have created a library that supports deeplinking on most of the modern mobile browsers. But this requires separate deeplinking page which needs to be hosted in different domain to support universal linking in ios9 facebook browser.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.