1

In reading the WebKit documentation, I see I can directly evaluate Javascript in the embedded browser. Great! This handles passing messages from the native OSX app into the website.

However, I also need to be able to pass messages from my Javascript to trigger some code in the OSX application. I know how I would do this on the iPhone UIWebView: I would implement the UIWebViewDelegate class, and then implement a method like this:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
     // Examine the request object and do whatever needs be done
     return NO;
}

Coincidentally, I see that other users have come up with this solution for the iOS. However, I see no equivalent method in the OSX WebKit framework (eg, within the Frame Load Delegate).

Can anyone suggest best practices for passing a message from my Javascript to my OSX app?

Community
  • 1
  • 1
Zane Claes
  • 14,732
  • 15
  • 74
  • 131

1 Answers1

0

Looks like I didn't dig deep enough before asking. In WebKit, you can directly call Objective-C methods from Javascript by exposing the Objective-C class. Check out this documentation: http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html

Very easy to use, and super useful.

EDIT For the sake of completeness: If you're looking for a way to intercept (and even block) page load calls (like I did in the UIWebView example above), check out the documentation for the WebKit policyDelegate. You can choose to ignore (or use) events of a certain type.

Zane Claes
  • 14,732
  • 15
  • 74
  • 131