开发者

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. On one particular controller i have a UIWeb开发者_运维问答View control that only occupies a small portion of the UIViewController screen real estate that i load html from a web service as a string.

[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???? 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:

You can then call [UIApplication openURL] to open 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜