On Oct 22, 2008, at 11:37 AM, Benjamin Dobson wrote:

My main WebView's method for opening windows is controlled via UIDelegate. These requests are passed on to a second WebView, which intercepts all requests via policyDelegate. It then passes them on to the default browser with the openURL: method in NSWorkspace.

Why create a second WebView? Just make the decision in your main WebView using the WebPolicyDelegate method
-webView:decidePolicyForNavigationAction:request:frame:decisionListener:
and send the listener an -ignore message (from WebPolicyDecisionListener protocol) if you decide to open the link in an external browser.

Here's an example:

// <WebPolicyDelegate>
// if the user clicks a link it loads the url in an external web browser // if a page is loaded progammatically (via loadHTMLString:baseURL: for example) then that link is opened by the WebView - (void)webView:(WebView *)sender decidePolicyForNavigationAction: (NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id <WebPolicyDecisionListener>)listener
{       
if ([[actionInformation objectForKey:WebActionNavigationTypeKey] intValue] != WebNavigationTypeOther) {
                [listener ignore];
                [[NSWorkspace sharedWorkspace] openURL:[request URL]];
        }
        else
                [listener use];
}

If you only want to use the external browser when the user tries to open a new window use webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener : instead.

--Nathan



_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to