Access Titanium.version from WebView
As I understand, a WebView does not have access any more to the Titanium object. Now I am looking for a way to determine the current version of Titanium in a JavaScript run within a WebView. Any hints are appreciated. Thanks.
5 Answers
-
Georg,
Where did you see that information. This would seem to be the root of the problems I am having with my WebView. If the WebView doesn't have access to the Titanium object, how should one architect a page that needs to be updated from a DB but also needs to display multi-column tables and HTML context.
-
Hi Peter,
argh, the current state of the documentation leaves a lot to be desired… I found this info here: [http://www.codestrong.com/timobile/changelog/0_9/] (Scroll all the way down to Webview). The proposed solution is to use custom events, but I don't see/understand how a custom event could help me with getting the version info of Titanium.
-
That's very interesting. The document states "You can use the Titanium.App.fireEvent and Titanium.App.addEventListener APIs to send/receive events to and from a web view, and you can use the Titanium.API logging APIs to log information from within a web view."
I have been able to find examples of fireEvent and even got it working in one of my apps but I need to get data into the webview so I guess I have to use addEventListener.
I'll have to play with that to see if I can open a webview and then call an event into it from the old window. Thanks again for the tip.
-
IN 1.3.2 and SDK 4 on IPHONE even KitchenSink is not working for me.. it does work partly in 3.2 , any chance this get fixed?
I can not call any API from webview ;(
-
Hey - I hope this can help anyone who still is struggling with this:
Say I have a web view called myWebView with a source of 'myWebView.html' (relative to the Resources folder).
In myWebView.html, I have a dom element (myDOM) with a click event attached to it:in myWebView.html
<script type="text/javascript> // ... code before has created myDOM // When myDOM is clicked, it will send an event to Ti.App: myDOM.addEventListener('click', function(){ Ti.Api.fireEvent('requestVersion'); }); // Listens to the answer from Ti.App: Ti.App.addEventListener('answerVersion', function(e){ // Now you can do whatever you want // with e.version within the web view alert('version: ' + e.version); }); </script>
in app.js (or elsewhere in your app)
// Listens for the request from the web view: Ti.App.addeventListener('requestVersion', function(){ Ti.App.fireEvent('answerVersion, {version:Ti.version}); });
This worked for me. Please post if you have a better way.