0

I have a app link something like this,

pudding://anime/87667266347

I want a kind of javascript to try to redirect to this url. and if redirection fails, do nothing, without alert and just stay on current page.

try{
    window.location.href = "pudding://anime/87667266347";
}catch(error){
    //do nothing
}

The code above seems can not dismiss the browser alert popup.

How can I achieve this?

Cao Dongping
  • 969
  • 1
  • 12
  • 29
  • 4
    What is `pudding://`? :D – 23tux Sep 04 '14 at 09:48
  • 1
    duplicate? http://stackoverflow.com/questions/2872090/how-to-check-if-a-custom-protocol-supported – red-X Sep 04 '14 at 09:49
  • 'browser alert popup' sounds like a security feature to prevent users from potentially dangerous auto-redirects. Are you trying to bypass client-side security features? (hint: this is bad) – Guy Flavell Sep 04 '14 at 09:50
  • 1
    You can do via ajax, but only for internal urls. If you want to ping external url then create a script or servlet on the server which does your job and sends the response to you, and use javascript to call it. – Voonic Sep 04 '14 at 09:52

1 Answers1

0

Finally I got the answer from this question How to check if an app is installed from a web-page on an iPhone?

$(function(){
        if (getQueryVariable("direct") == null) {
            setTimeout(function() {
                window.location.href = window.location.href + "?direct=no";
            }, 10);
            window.location = "pudding://anime/53b80d30abacae00038b4568";
        }
    });
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
       return null;
    }
Community
  • 1
  • 1
Cao Dongping
  • 969
  • 1
  • 12
  • 29