admin管理员组

文章数量:1391974

I am developing a application using Phonegap for Android and iphone. I need to change the screen orientation when i am navigating from one page to another. Can any one tell how it can be done through either java script or jquery ?

Thank you

I am developing a application using Phonegap for Android and iphone. I need to change the screen orientation when i am navigating from one page to another. Can any one tell how it can be done through either java script or jquery ?

Thank you

Share Improve this question asked Jul 20, 2012 at 3:52 tilaktilak 4,7016 gold badges35 silver badges46 bronze badges 3
  • I think you can't, since neither JavaScript nor jQuery (wrote in JavaScript) can do this as far as I know. – davidbuzatto Commented Jul 20, 2012 at 3:55
  • Do you mean "adapt my output to the current screen orientation", not "change the device's screen orientation"? – ryandenki Commented Jul 20, 2012 at 3:59
  • You know jQuery can't do anything that JavaScript can't do, right? (Because jQuery is "just" a JavaScript library.) – nnnnnn Commented Jul 20, 2012 at 4:05
Add a ment  | 

1 Answer 1

Reset to default 6

You can try this:

$(window).resize(function() {
    var height = $(window).height();
    var width = $(window).width();

    if (width > height) {
        // Landscape
        $("#mode").text("LANDSCAPE");
    } else {
        // Portrait
        $("#mode").text("PORTRAIT");
    }

});

Another one id window.orientation which return 0, 90 or -90 where:

  • 0 stands for: portrait mode

  • 90 stands for: landscape mode with the screen turned to the left

  • -90 stands for: landscape mode with the screen turned to the right

     window.onorientationchange = function() 
    {
    var orientation = window.orientation;
    switch(orientation) {
        case 0:
            //Top side up.
            break; 
    
        case -90:
            //Left side up (turned 90 degrees to the right)
            break;
    
        case 90: 
            //Right side up (turned 90 degrees to the left)
            break;
      }
    }
    

You can also see

Detect rotation of Android phone in the browser with JavaScript for info.

本文标签: How can i change Screen Orientation using javascript or JqueryStack Overflow