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
0 Comments

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 )

    http://developer.appcelerator.com/question/10671/webview-dom

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

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

    http://developer.appcelerator.com/question/26971/fireevent-from-remote-url-on-iphone

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

    — answered July 22nd 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.