开发者

Getting Objective-C to talk to JavaScript with UIWebView

I am building an iPad app that loads local html files开发者_JAVA百科 in a UIWebView. I have an int stored in a view controller that I want to use to determine what content to load into the html document.

Additionally, I want to have clickable links in the html that create generate new, smaller UIWebViews on the highest layer, like a "pop-up".

How does one send data back and forth from Obj-C to Javascript?


You can send data from the Cocoa layer to the JavaScript layer by using the stringByEvaluatingJavaScriptFromString: method in UIWebView.

The Cocoa layer can also "intercept" link clicks by implementing the UIWebViewDelegate protocol in your view controller; when a link is clicked, the delegate method webView:shouldStartLoadWithRequest:navigationType: will be called, at which point the Cocoa layer can do the kind of "pop-up" action you're looking for.

(Although I would ask you why you want to generate pop-ups like this. My gut feeling tells me that this will look and feel quite annoying from the user's point of view.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜