PDA

View Full Version : UIWebView javascript to objective-c bridge?




necubi
Aug 10, 2008, 03:32 AM
Hi all,

In the regular cocoa WebView there is a method [webview windowScriptObject] which returns an object that lets you expose objective-c objects to javascript running inside the webview. However, that method does not seem to exist for UIWebView, and I have been able to find no information about it in the docs. It appears that there was a delegate method
- (void)webView:(WebView *)sender windowScriptObjectAvailable:(id)windowScriptObject

in 1.1.2/3/4 from sample code I've found, but that does not work in 2.0. Does anybody have any clue how to get the windowScriptObject or of any other means of sending a message from javascript running in a webview to objective-c? In particular, I want to be able to do something in Obj-C when the user clicks a link or scrolls in the webview, both of which would be easily accomplishable in cocoa.

Any help would be greatly appreciated.



slycrel
Aug 10, 2008, 11:48 PM
Check out this link, sounds like it's exactly what you need. Well, conceptually, with a code example that does something similar. =)

http://discussions.apple.com/thread.jspa?messageID=7731057&#7731057