4

I have an HTML page containing a link to a custom URL scheme, displayed on iPhone .e.g myapp://localhost/

Assuming the user clicks it, but there is no app that can respond to this scheme, how do I catch this in javascript (that the link cannot be opened)?

tnx

Sagi Mann
  • 2,967
  • 6
  • 39
  • 72
  • Just because you rephrased it, doesn't make it any different: [how do I detect if window.location failed?]. Unless you are no longer talking about Javascript, in which case it should not be tagged as such. (http://stackoverflow.com/questions/18404148/how-do-i-detect-if-window-location-failed) – CodingIntrigue Aug 23 '13 at 13:59
  • 1
    @sagimann Are you using a `UIWebView` by any chance to display this html page? – Amar Aug 23 '13 at 14:06
  • See also:http://stackoverflow.com/questions/6964515/launching-app-or-app-store-from-safari – Amar Aug 23 '13 at 14:13

1 Answers1

0

Yes that can be done using webview delegate not using Javascript.

Similar question How to handle app URLs in a UIWebView?

- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

// Determine if we want the system to handle it.
NSURL *url = request.URL;
if (![url.scheme isEqual:@"http"] && ![url.scheme isEqual:@"https"]) {
    if ([[UIApplication sharedApplication]canOpenURL:url]) {
        [[UIApplication sharedApplication]openURL:url];
        return NO;
    }
}
return YES;
}
Community
  • 1
  • 1
Vaibhav Gautam
  • 2,074
  • 17
  • 17