Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

COFFEECATCODING


抱着猫咪 喝着咖啡 写写代码

webView - 用系统浏览器打开链接

如果使用的是a标签,可以直接用下面的代码:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *requestURL =[request URL];
if (([[requestURL scheme] isEqualToString: @"http"] || [[requestURL scheme] isEqualToString:@"https"] || [[requestURL scheme] isEqualToString: @"mailto" ])
    && (navigationType == UIWebViewNavigationTypeLinkClicked))
{
    return ![[UIApplication sharedApplication] openURL:requestURL];
}
return YES;

}

如果是通过侦听onclick事件来触发的,会有点不同:

navigationType == UIWebViewNavigationTypeOther

而且如果加载的页面有跳转之类的上面这个判断也会是True.