0

I am targeting iOS 7.0.4 as that is the current version. I have a help page in my app that is just html. I have links in there that go to our company website, but I don't want them to open in the app, I want to launch safari.

I tried everything in this question: How to open Safari from a WebApp in iOS 7

Nothing really works.

The link keeps opening in the app, which means there's no browser goodies, like a back button, or url bar, and even the pinch zoom seems all weird.

Here's the relevant line of html code:

<p style="font-family:arial;font-size:60px;">Visit us on the web at 
<a href="http://ourcompany.com" target="_xxx">ourcompany.com</a>

I tried numerous things in the target such as "_new", "_blank" or just not having it at all.

This is the code that loads the html:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    NSString *path = [[NSBundle mainBundle] pathForResource:@"capitalsHelp" ofType:@"html"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [_webView loadRequest:request];
}
Community
  • 1
  • 1
jgritty
  • 11,660
  • 3
  • 38
  • 60

1 Answers1

1

Supposing you are using a UIWebView to present html, you can do the following:

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

    return YES;
}

on the UIWebView's delegate.

Tassos
  • 3,158
  • 24
  • 29