title: WebKit in an OSX App: Passing messages from Javascript to the wrapper application?
body: <p>In reading the WebKit documentation, I see I can <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/JavaScriptFromObjC.html#//apple_ref/doc/uid/30001214-BCIIEAFH" rel="nofollow noreferrer">directly evaluate Javascript in the embedded browser</a>. Great! This handles passing messages from the native OSX app into the website.</p>
  
  <p>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 <strong><em>iPhone UIWebView</em></strong>: I would implement the UIWebViewDelegate class, and then implement a method like this:</p>
  
  <pre><code>- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
       // Examine the request object and do whatever needs be done
       return NO;
  }
  </code></pre>
  
  <p>Coincidentally, I see that <a href="https://stackoverflow.com/questions/3742590/nsstring-in-webview-iphone-and-objective-c/3742635#3742635">other users have come up with this solution for the iOS</a>. However, I see no equivalent method in the OSX WebKit framework (eg, within the <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/LocationChanges.html#//apple_ref/doc/uid/20002027-CJBEHAAG" rel="nofollow noreferrer">Frame Load Delegate</a>).</p>
  
  <p>Can anyone suggest best practices for passing a message from my Javascript to my OSX app?</p>