Skip to content

Instantly share code, notes, and snippets.

@dasher
Created July 6, 2010 17:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dasher/465698 to your computer and use it in GitHub Desktop.
Save dasher/465698 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>
Copy link

ghost commented Dec 21, 2010

I keep getting the error "Ti is not defined" in Firebug of my web browser.

I tried it on my device too and I can't get any message from Ti to the web browser.

Is there some javascript include that I'm forgetting?

I hope you can help,

@samredway
Copy link

You and I both hynese. Was there ever any resolution to this issue?

EDIT:

Ok this is solved by adding this line to your html script:

var Ti = window.parent.Ti;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment