Skip to content

Instantly share code, notes, and snippets.

@pegli
Created October 1, 2014 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pegli/30ea3b3b29bcb5ff104a to your computer and use it in GitHub Desktop.
Save pegli/30ea3b3b29bcb5ff104a to your computer and use it in GitHub Desktop.
Ti webview eventing
var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({
url: 'local.html'
});
var button = Ti.UI.createButton({
title: 'fromTitanium',
height: '50dp',
width: '130dp'
});
button.addEventListener('click', function(e) {
Ti.App.fireEvent('app:fromTitanium', { message: 'event fired from Titanium, handled in WebView' });
});
Ti.App.addEventListener('app:fromWebView', function(e) {
alert(e.message);
});
win.add(webview);
win.add(button);
win.open();
<html>
<head>
<script>
Ti.App.addEventListener("app:fromTitanium", function(e) {
alert(e.message);
});
</script>
</head>
<body>
<button onclick="Ti.App.fireEvent('app:fromWebView', { message: 'event fired from WebView, handled in Titanium' });">fromWebView</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment