• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: WebView: Open new windows in default browser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WebView: Open new windows in default browser


  • Subject: Re: WebView: Open new windows in default browser
  • From: Nathan Kinsinger <email@hidden>
  • Date: Thu, 23 Oct 2008 13:21:54 -0600

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@hidden)

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:
This email sent to email@hidden


References: 
 >WebView: Open new windows in default browser (From: Benjamin Dobson <email@hidden>)

  • Prev by Date: Re: CGPoint wrapper?
  • Next by Date: Re: enumerating the NSApplication instances?
  • Previous by thread: WebView: Open new windows in default browser
  • Next by thread: Re: WebView: Open new windows in default browser
  • Index(es):
    • Date
    • Thread