Titanium Community Questions & Answer Archive

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

externally calling a function within a local webview

I posted a similar question a few weeks ago, and it got buried in the forums unanswered. Here it is again hopefully clarified more:

I am trying to create a function within a local webview html that can be called from outside the webview.
I have code inside my webview's html saying:

function fu()
{
alert("hello!");
};

Ti.App.addEventListener("bar", function()
{
fu();
});

I can fire the alert from within the webview's html code by calling either:

fu();

or

Ti.App.fireEvent("bar");

Unfortunately I can't seem to trigger the alert from outside the html in the containing app.js.
I have tried calling both:

Ti.App.fireEvent("bar");

and

webview.evalJS("fu();");

from the app.js. Neither trigger the alert.
Any idea what I'm doing wrong?

Thanks much,
-Matt

— asked April 16th 2010 by Matthew Woods
  • webview
0 Comments

1 Answer

  • create an onload event in the webview that will let the app.js know that is ready to receive events.
    I had to set this to 500ms -1000ms to work properly.

    — answered April 16th 2010 by Dan Tamas
    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.