3

Im creating a website using MVC 4, and I have a need to within a javascript open an application, using an url-scheme (surfing the site using a mobile device) If the application is not installed, I need the javascript to redirect to google play.

I have looked and tried all various methods mentioned in threads like this: How to fall back to marketplace when Android custom URL scheme not handled?

Many of those solutions relies on a timeout-event, which will redirect to another website if the app is not installed. The problem I am encountering is that after I have used the window.location = URL; in my javascript, any timeouts I have created seems to just dissapear. If i skip the window.location = URL; my timeouts fire just fine and redirects to google play or whatever. Does anyone understand why i am having this problem?

As I said im using MVC 4, and executes a javascript within a simple view. I have tried many different codes, opening iframes etc, all resulting in the same problem mentioned above. I just tried opening the app, and delaying an ITunes redirect on a iPhone-device using Safari, it seems to work. Can the same be achieved with android/chrome?

I would appreciate any help I could get considering this.

Community
  • 1
  • 1
Davidmage
  • 31
  • 1
  • 2

2 Answers2

2

Opening an app using iframe is no longer supported by Google Chrome (v25 onwards). You can refer to the example on Android Guidelines for opening the app (if installed) or redirecting to market.

Akshat Singhal
  • 1,801
  • 19
  • 20
-1

I love the Skype solution:

var element = document.createElement('iframe');
element.id = '_the_frame_' = ((new Date()).getTime();
document.appendChild(element);           
var r = document.getElementById(element.id);
var u = true;
window.addEventListener("pagehide", function () { u = false; }, false);
if (r !== null) {
         r.src = _customSchemaUrl;
 }
 setTimeout(function() {
 if (u) {
       window.location = _downloadIosUrl;
    }
}, 2000);
ozlevka
  • 1,988
  • 16
  • 28
  • errors at line2 (invalid left-hand assignment) at line3, document.body.appendChild also the script itself doesnt do its job – mmln Jun 23 '14 at 13:26