Web View, detect orientation
Why doesnt the following code work within a webview, it works fine as normal html from a webpage.
app.js
var webview = Titanium.UI.createWebView({url:'index.html'});
var win = Titanium.UI.createWindow();
win.add(webview);
win.open();
index.html
<html>
<head>
<script>
window.onorientationchange = function(){
if ( orientation == 0 ) {
alert(orientation);
}
else if ( orientation == 90 ) {
alert(orientation);
}
else if ( orientation == -90 ) {
alert(orientation);
}
else if ( orientation == 180 ) {
alert(orientation);
}
};
var orientation = window.orientation;
alert(orientation);
</script>
</head>
</html>
4 Answers
-
Has anyone come across this before, would I have to detect the orientation in the normal app.js and then pass it to the webview, how do I go about this?
-
I'm having the same issue right now. Did you ever figure this out?
-
Try the Ti.Gesture API in the HTML file, because I am pretty sure that in local HTML files you can call upon Titanium's APIs, just not in remote files.
-
Ti.Gesture doesn't work for me, but adding an event listener for a Ti.App.event does. So I fire a custom event from the app to the html file. Unfortunately this results in a delay, but it's better than nothing.