Titanium Community Questions & Answer Archive

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

Trigger link to new screen from inside UIwebview?

We have a section of our app that is constructed using styled HTML in a Uiwebview to present data.

We have icons/buttons inside that webview that need to trigger links to other screens/views inside the app. Eg one icon links to info panel etc…

This is pretty trivial in xcode but can't seem to find a method that works in titanium?

Any hints gratefully received.

— asked December 2nd 2010 by Alex Morris
  • link
  • mobile
  • views
  • webview

1 Answer

  • Accepted Answer

    here is a webview with a link that fires an event

    var webView = Ti.UI.createWebView({
                height : '100%',
                width : '100%'
    var htmlStr = "<a href='#' onclick=\"Ti.App.fireEvent('calledFromWebView',{val:10});\">click me</a>";
    webView.html =  "<html><body>" + htmlStr + "</body></html>";

    here is an application event listener that will capture the event

    Ti.App.addEventListener('calledFromWebView', function(data) {
        Ti.API.log("From WebView " + data.val);

    notice how the data is passed back to the event, this allows you to get information from the webView back into your application

    output in the log should be

    [INFO] From WebView 10
    — answered December 2nd 2010 by Aaron Saunders
    1 Comment
    • Thanks Aaron. We came to pretty much the same conclusion. Wasn't super obvious at first!

      — commented December 2nd 2010 by Alex Morris
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.