Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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>
— asked November 15th 2010 by Gary Everest
  • detect
  • ipad
  • orientation
  • webview
0 Comments

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?

    — answered November 16th 2010 by Gary Everest
    permalink
    0 Comments
  • I'm having the same issue right now. Did you ever figure this out?

    — answered April 7th 2011 by Phi Chong
    permalink
    0 Comments
  • 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.

    — answered April 7th 2011 by Colton Arabsky
    permalink
    0 Comments
  • 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.

    — answered October 26th 2011 by Klaus Heyne
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.