PDA

View Full Version : Cocoa WebView to Open Links in Default Browser




nikiski
Apr 7, 2008, 10:27 PM
Hi all,

I'm wondering if there is a way to make a WebView to open a link with the system's default browser?

Thanks.



kainjow
Apr 7, 2008, 11:25 PM
You need to set the web view's policy delegate, and then implement the webView:decidePolicyForNavigationAction:request:frame:decisionListener: method, something like this:

- (void)webView:(WebView *)sender
decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id <WebPolicyDecisionListener>)listener
{
[listener ignore];
[[NSWorkspace sharedWorkspace] openURL;[request URL]];
}


Edit: I can't get that code to format, but it should do what you need.