Titanium Community Questions & Answer Archive

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

problems firing an event listened for in a webview

I have a function in a local webview that I am trying to call from an outside Javascript.

I have added the function:

Titanium.App.addEventListener("drawLines", function()
{
myDrawFunction();
});

When I call the function from within the webview's html using:

Titanium.App.fireEvent("drawLines");

The function gets called, however if I put the same firing line in the .js file that defines the webview, the function is not called.

Any idea what I'm doing wrong?

Thanks.

-Matt

— asked March 25th 2010 by Matthew Woods
  • event
  • webview
1 Comment
  • I'm seeing problems whenever I use an inner function as well. For example, this works (when provided to a JQuery click, for example):

    function(name) { return function() { window.ruby_stuff.testout(name); }; }("abc")

    … but this does not (with a variable reference):

    function(name) { return function() { window.ruby_stuff.testout(name); }; }(sample_var)

    I think nested functions are a problem. I'd love to hear solutions to this.

    — commented June 20th 2011 by Trent Larson

7 Answers

  • I think the webview inner js has a different context from the js file defining the webview.
    the only thing they have in common is titanium.app.fireevent and addeventlistener

    — answered March 25th 2010 by Dan Tamas
    permalink
    0 Comments
  • Any idea how I can get a command in?

    I've tried using the evalJS function to do both:

    webview.evalJS("myDrawFunction();");
    webview.evalJS("Titanium.App.fireEvent("drawLines");");

    neither seem to trigger the function.

    — answered March 25th 2010 by Matthew Woods
    permalink
    0 Comments
  • I'm not sure I understand what you want to do.

    — answered March 26th 2010 by Dan Tamas
    permalink
    0 Comments
  • I am trying to use the following vector graphics library:
    http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm#browser

    It works great within a local url webview, but I couldn't get it working outside of the webview.

    I am trying to create a blank webview "canvas" window with externally accessible functions so I can draw lines into it from the app.js that contains the webview.

    — answered March 26th 2010 by Matthew Woods
    permalink
    0 Comments
  • I have very similar problem.

    in app.js I have added an event listener , and in a web view one of the linked js files have Ti.App.fireEvent .
    with ver 1.0 it worked fine , since 1.2 the event is not captured and I do not see it runing ..

    — answered April 14th 2010 by Yosi Oren
    permalink
    0 Comments
  • As far as I'm aware / tested, Ti.App is not available in external URL's.

    — answered September 29th 2011 by James Adams
    permalink
    0 Comments
  • I'm experiencing a problem where I can open a webview, trigger an event, navigate to another local file (hosted on the iPad, except it's loaded via the <a href> instead of Ti changing the current page) but I can no longer trigger an event - it's as if the Ti context is no longer available.

    How does one get around that, how do I make the context available for the second/third/etc pages which are accessed locally through the webview?

    — answered February 28th 2012 by P Sweeney
    permalink
    0 Comments
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.