Skip to content

Instantly share code, notes, and snippets.

@egomez99
Created August 6, 2014 18:29
Show Gist options
  • Save egomez99/9eb0983c8b3a4bf39dbd to your computer and use it in GitHub Desktop.
Save egomez99/9eb0983c8b3a4bf39dbd to your computer and use it in GitHub Desktop.
var win = Ti.UI.createWindow({
layout : 'vertical'
});
var view = Ti.UI.createView({
top : 0,
height : 50,
});
var webview = Ti.UI.createWebView({
top : 5,
height : Ti.UI.SIZE,
url : 'logging.html'
});
var button = Ti.UI.createButton({
top : 45,
title : 'fromTitanium',
height : '50dp',
width : '130dp'
});
button.addEventListener('click', buttonClicked);
function buttonClicked(e) {
Ti.App.fireEvent('app:fromTitanium', {
message : 'event fired from Titanium, handled in WebView'
});
}
function fromWebView(e) {
//Your logs
alert(e.message);
Ti.API.info('FromWebView: Event msg: '+ e.message);
}
Ti.App.addEventListener('app:fromWebView', fromWebView);
var button2 = Ti.UI.createButton({
top : 25,
title : 'CleanUp',
height : '50dp',
width : '130dp'
});
button2.addEventListener('click', cleanUp);
function cleanUp() {
if (webview != null) {
view.remove(webview);
webview.release();
}
webview = null;
button.removeEventListener('click', buttonClicked);
Ti.App.removeEventListener('app:fromWebView', fromWebView);
Ti.App.fireEvent('app:fromTitanium', {
message : 'event fired from Titanium, after removing WebView'
});
}
view.add(webview);
win.add(view);
win.add(button);
win.add(button2);
win.open();
<html>
<head>
<script>
function fromTitanium(e) {
alert(e.message);
}
Ti.App.addEventListener("app:fromTitanium", fromTitanium);
</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