Access Titanium API from WebView's JavaScript?
How do I do native things (such as open a new Window, or use the camera) when the user taps a button in a WebView?
3 Answers
-
Accepted Answer
You can do this only from a webview with a local source ( not a remote one ) using events.
Take a look here ( 3rd post )
http://developer.appcelerator.com/question/10671/webview-dom
Here is setting a variable, but you can adapt it.
-
If it's a remote url,
First you have to create an Ti event listener somefunction, on that remote url button or link, you add this Ti.App.fireEvent('somefunction') for triggering. That should be working for android last time i heard.
But for iphone/ipad, you'll need that to be a locate web, not remote web. So the get-around is after finished the step above, you have to assign your webview html content using XHR to get the remote content first, or from a temp webview. I use both on different apps. XHR is faster as it doesn't load the web content media first.
Like this for example.
http://developer.appcelerator.com/question/26971/fireevent-from-remote-url-on-iphone
-
smart :)