LoginSignup
3
3

More than 5 years have passed since last update.

Open links in WebView with user's default browser on clicking them

Posted at

Set policyDelegate of a WebView to some class and implement the delegate method below in the class.

- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener {
  if ([[actionInformation valueForKey:WebActionNavigationTypeKey] intValue] == WebNavigationTypeLinkClicked) {
    [[NSWorkspace sharedWorkspace] openURL:request.URL];
    [listener ignore];
  } else {
    [listener use];
  }
}

MacAppならありがちな挙動なのに意外とドキュメントに書いてない&探しても見付からなくて時間かかった.ので英語で書いておく.

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3