Skip to content

Instantly share code, notes, and snippets.

@pietromalerba
Forked from dasher/app.js
Created March 28, 2013 21:54
Show Gist options
  • Save pietromalerba/5267161 to your computer and use it in GitHub Desktop.
Save pietromalerba/5267161 to your computer and use it in GitHub Desktop.
Titanium.UI.setBackgroundColor('#000');
// Create a window
var win = Titanium.UI.createWindow({
title:'Web Test',
backgroundColor:'#fff'
});
// and now a webView
var webview1 = Titanium.UI.createWebView({url:'somePage.html'});
// Attach an APP wide event listener
Ti.App.addEventListener('webToTi', function(e) {
Ti.API.info('webToTi Sent:'+e.test);
});
// Add the webView to the window
win.add(webview1);
// Create a timeout - we want time for the window to be ready before we fire the event
setTimeout(function(e){
Ti.App.fireEvent("webPageReady", {message:"bob"});
},10000); // 10s should be enough :)
// Open the Window
win.open();
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body id="mybody" style="height:500px;background-color:#999">
Hello from local webview. You should see an indicator in the middle and my text should be blue.
We are also including JQuery
<div id="foo" style="margin-top:20px;font-weight:bold">hello</div>
<script>
Ti.App.addEventListener('webPageReady',function(e) {
alert('The word is ' + e.message);
});
</script>
<script>
var payload = {test:"fred"};
Ti.App.fireEvent('webToTi', payload);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment