3

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

tilak
  • 4,589
  • 6
  • 34
  • 45
  • I think you can't, since neither JavaScript nor jQuery (wrote in JavaScript) can do this as far as I know. – davidbuzatto Jul 20 '12 at 03:55
  • Do you mean "adapt my output to the current screen orientation", not "change the device's screen orientation"? – ryandenki Jul 20 '12 at 03:59
  • You know jQuery can't do anything that JavaScript can't do, right? (Because jQuery is "just" a JavaScript library.) – nnnnnn Jul 20 '12 at 04:05

1 Answers1

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.

Community
  • 1
  • 1
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164