简体   繁体   English

UIView中的UIWebView需要链接才能在浏览器中打开

[英]UIWebView in UIView need links to open up in browser

So i have an app that is not so much a webapp but more uses UIViewControllers and UIViews for most screens. 因此,我有一个不是Web应用程序的应用程序,而是大多数屏幕使用UIViewControllers和UIViews的应用程序。 On one particular controller i have a UIWebView control that only occupies a small portion of the UIViewController screen real estate that i load html from a web service as a string. 在一个特定的控制器上,我有一个UIWebView控件,该控件仅占UIViewController屏幕空间的一小部分,我从Web服务中以字符串形式加载html。

[self.webView loadHTMLString:marketingBlurb baseURL:nil];

what i'm wondering is if the html links in this string can open up on the browser and not in the UIWebView in my app???? 我想知道的是,此字符串中的html链接是否可以在浏览器中打开,而不能在我的应用程序的UIWebView中打开? How can i do this?? 我怎样才能做到这一点?? Is this even possible ? 这有可能吗?

Set the delegate of the webview to self , and intercept all links using webView:shouldStartLoadWithRequest:navigationType: 将webview的委托设置为self ,并使用webView:shouldStartLoadWithRequest:navigationType拦截所有链接

You can then call [UIApplication openURL] to open Safari. 然后,您可以调用[UIApplication openURL]打开Safari。

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

  return YES;
}

I didn't test this code, but it will get you started. 我没有测试此代码,但是它将帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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