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