I am building an iPad app that loads local html files 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 inUIWebView.The Cocoa layer can also “intercept” link clicks by implementing the
UIWebViewDelegateprotocol in your view controller; when a link is clicked, the delegate methodwebView: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.)