简体   繁体   中英

Need to open link in safari from uiwebview?

我已将整个html文档与转义序列存储在变量中...并且它包含一些锚标记..如果已经点击了它,它应该在safari中打开,而不是在我的应用程序webview中....

You can use following code for that.

   -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
        if ( inType == UIWebViewNavigationTypeLinkClicked ) {
            [[UIApplication sharedApplication] openURL:[inRequest URL]];
            return NO;
        }

        return YES;
    }

You can use the UIWebViewDelegate protocol to achieve this:

// assuming webView is a valid UIWebView
webView.delegate = self;

- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)rq navigationType:(UIWebViewNavigationType)nt
{
    if (nt == UIWebViewNavigationTypeLinkCkicked) {
        [[UIApplication sharedApplication] openURL:[rq URL]];
        return NO;
    }

    return YES;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM