Re: [OT?] Intercept Links in WebView
Re: [OT?] Intercept Links in WebView
- Subject: Re: [OT?] Intercept Links in WebView
- From: malcom <email@hidden>
- Date: Wed, 8 Mar 2006 13:45:51 +0100
thank you keith! it works fine :)
On 3/8/06, Keith Blount <email@hidden> wrote:
> 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
>
--
www.malcom-mac.com
mac/win software development
email@hidden
_______________________________________________
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