Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17089

Open safari from webview

$
0
0

@sefiroths wrote:

Hi, I'd like to open browser from a webview.
using a link with target="_blank" don't do anything.
I have made this change to UIWebViewImpl-ios.mm but I don't know if it is the best way:

#pragma mark - UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString *url = [[request URL] absoluteString];
    /***** added *****/
    BOOL isExternalLink = [[[request URL] scheme] isEqualToString:@"http"];
    if (isExternalLink && (navigationType == UIWebViewNavigationTypeLinkClicked)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
        return YES;
    }         
    /***** finished *****/


    if ([[[request URL] scheme] isEqualToString:self.jsScheme]) {
        self.onJsCallback([url UTF8String]);
        return NO;
    }
    if (self.shouldStartLoading && url) {
        return self.shouldStartLoading([url UTF8String]);
    }
    return YES;
}

However is not cross platform.
There is a better way?
If not how can I make this solution work for android and eventually fow win?
thanks

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>