Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked March 11th 2010 by Georg von der Howen
  • #webview

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.

    — answered March 11th 2010 by Peter Amiri
  • 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.

    — answered March 11th 2010 by Georg von der Howen
  • 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.

    — answered March 11th 2010 by Peter Amiri
  • 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 ;(

    — answered July 15th 2010 by Petr Cervenka
  • 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(){
    // 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);

    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.

    — answered May 22nd 2011 by Regis Zaleman
    1 Comment
    • NOTE. Communication from the html in a webview to your app using fireEvent works providing that your html is local to the app - ie. it is contained in an html file located in your app's resources folder.

      This does not work if the html containing the Ti.Api.fireEvent JS call is located remotely relative to your app.

      — commented June 24th 2011 by Laurence Kirchmeier
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.