• 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: [OT?] Intercept Links in WebView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [OT?] Intercept Links in WebView


  • Subject: RE: [OT?] Intercept Links in WebView
  • From: Keith Blount <email@hidden>
  • Date: Wed, 8 Mar 2006 04:43:11 -0800 (PST)

Hi,

Yes, I do exactly this so that links are opened up in
the default browser rather than within my web view.
You can do it via the web view's policy delegate
method:

-webView:decidePolicyForNavigationAction:request:frame:

(Obviously you need to call [webView
setPolicyDelegate:yourDelegate] for this method to get
called.)

I just use a code snippet from the Adium source to
open links in an external browser, which I've copied
below. Note that if you want to catch the link for
something different, you can see that you grab the URL
using:

NSURL *url = [actionInformation
objectForKey:WebActionOriginalURLKey];

Here's the delegate method from Adium:

// Ensures that web links are opened in the default
browser, so that navigation is disallowed within our
web view itself
// Code from
http://penguinmilitia.net/svn/adium/tags/AdiumX_0-60/adium/Plugins/WebKit Message View/AIWebKitMessageViewController.m
- (void)webView:(WebView *)sender
    decidePolicyForNavigationAction:(NSDictionary
*)actionInformation
		request:(NSURLRequest *)request
		  frame:(WebFrame *)frame

decisionListener:(id<WebPolicyDecisionListener>)listener
{
    int actionKey = [[actionInformation objectForKey:
WebActionNavigationTypeKey] intValue];
    if (actionKey == WebNavigationTypeOther)
	{
		[listener use];
    }
	else
	{
		NSURL *url = [actionInformation
objectForKey:WebActionOriginalURLKey];
		[[NSWorkspace sharedWorkspace] openURL:url];
		[listener ignore];
    }
}

Hope that helps.
All the best,
Keith

--- ORIGINAL MESSAGE ---

Hello list,
Is possible to intercept links from WebView with
Cocoa/ObjC? Is there
a delegate methods/event that contains the clicked
url?
Thanks

(also posted on Webkit ML)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [OT?] Intercept Links in WebView
      • From: malcom <email@hidden>
  • Prev by Date: Re: [OT?] Intercept Links in WebView
  • Next by Date: Re: [OT?] Intercept Links in WebView
  • Previous by thread: Re: [OT?] Intercept Links in WebView
  • Next by thread: Re: [OT?] Intercept Links in WebView
  • Index(es):
    • Date
    • Thread