I am having trouble creating an Ti.App.addEventListener in a webview. Am I missing something? When I try to run the following code, the app crashes (Titanium SDK 4.2 | Android APIs 2.3):
app.js:
var win = Titanium.UI.createWindow({ backgroundColor:'#330' });
var webview = Titanium.UI.createWebView({ url: 'test.html' });
win.open(); win.add(webview);
test.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Test of titanium addEventListener
<script>
Titanium.App.addEventListener('hideWords',function(e) {
// empty function
});
</script>
</body>
</html>
2 Answers
A follow up for anyone else having the same problem. It appears that the Android emulator for 2.3 has a bug which causes issues with the webview. Try using APIs 2.2 or lower until a new emulator is released. Apparently Gingerbread on the device works properly. You can see more about this issue here:
http://code.google.com/p/android/issues/detail?id=12987
It is not clear what you are trying to do, but I think I would suggest the following approach.
- attach the eventListener to the webView, don't include it in the html code
- when the event is triggered, run some javascript code against the HTML in the webView to perform the desired actions; see Titanium.UI.WebView.evalJS
Your Answer
Think you can help? Login to answer this question!