1

I have certain doubts regarding WebKit Framework in cocoa...please clarify them.

  1. Can cocoa application forward/or receive parameters to the web application? If yes then what will be the mechanism for that?
  2. Can cocoa application respond(e.g. UI change, or alert msg) accordingly based on the web application i/p or o/p parameters?
  3. Will it be possible for cocoa application to call external(web app) Java Script/or Java Code?

1 Answer 1

3

In the case that you are hosting a WebKit WebView in your application :-

  1. Objective-C in your application can call Java Script in the hosted page. Use the WebView windowScriptObject message to retrieve an object that you can call evaluateWebScript on.

  2. Javascript in the hosted page can call Objective-C code in your app: You need to advertise callable methods by implementing the WebScriptObject protocol. The critical part is you call [[theView windowScriptObject] setValue:someobjectthatimplementstheprotocol forKey:@"callme"]. Javascript can then call "callme.someMethod(blah)", which will interrogate your object to see if it supports someMethod and then call it.

the html could look something like this iirc:

<button onClick="callme.someMethod()" .../>
2
  • thx Chris but is there any way available so that i can know that whether user ha clicked on some button or link in the web page?
    – Sid
    Nov 29, 2010 at 9:09
  • If the button click is implemented as java script then it can call your obj-c code via the WebScriptObject callback protocol. If the click is on a simple link type element, then WebView has a delegate interface iirc that gets notified of progress, and navigations and so on. Nov 29, 2010 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.