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 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?

— asked July 22nd 2010 by Brian Blakely
  • 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 )


    Here is setting a variable, but you can adapt it.

    — answered July 22nd 2010 by Dan Tamas
  • 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.


    — answered July 22nd 2010 by Daniel Lim
  • smart :)

    — answered July 22nd 2010 by Dan Tamas
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.