Thread-topic: Targeting clicks on links within a webview
User-agent: Microsoft-Entourage/12.1.0.080305
> Message: 1
> Date: Thu, 15 May 2008 11:13:44 -0400
> From: Troy Davis <email@hidden>
> Subject: Targeting clicks on links within a webview to the default
> browser
> To: email@hidden
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset="us-ascii"
>
> Another aspect of the application I'm working on is a webview that
> displays links from an RSS feed. I really don't want to load the
> resulting page into the little webview I have setup, I'd like to
> retarget any clicks in the webview to be launched in the default
> browser. Is this possible?
>
> I've tried this:
>
> set myBrowser to a reference to application "Safari"
> set delegate to call method "setDownloadDelegate:" of class "WebView"
> with parameter myBrowser
>
> But that doesn't work, and it's not necessarily the default browser
> either.
>
> I also tried the "External" focus ring option, but I think that's used
> for some other purpose.
>
> Any pointers are greatly appreciated!
>
> Thank You,
> Troy
I think this is best done on the Cocoa side in Obj-C. You can
designate/connect a policy delegate ("policyDelegate" to be specific) for
the webView in Interface Builder. Within your implementation of the
delegate, use some code like this to intercept the clicking of links and
send them to the default browser:
--
#import "webPolicy.h"
@implementation webPolicy
- (void)webView:(WebView *)sender
decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener>)listener {
int i = [[actionInformation objectForKey:@"WebActionNavigationTypeKey"]
intValue];
if ( i == WebNavigationTypeLinkClicked ) {
NSURL *url = [actionInformation
objectForKey:@"WebActionOriginalURLKey"];
[[NSWorkspace sharedWorkspace] openURL:url];
[listener ignore];
return;
} else {
[listener use];
}
}
@end
--
Where "webPolicy.h" is:
--
#import <Cocoa/Cocoa.h>
#import <WebKit/WebView.h>
#import <WebKit/WebPolicyDelegate.h>
@interface webPolicy : NSObject
{
}
@end
--
This sends all clicks on links to the browser. If needed, you can refine
this even further, to look at the contents of the URL and decide which links
should be handled in the webView and which should be sent to the browser.
Good luck!
Craig
--
Dr. Craig Hunter
NASA Langley Research Center
Configuration Aerodynamics Branch
email@hidden
(757) 864-3020
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Studio mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden
This email sent to email@hidden