1

Is there any way to keep mobile website in landscape mode on mobile devices?

Can we do it using any JavaScript code?

Darpan Kulkarni
  • 1,362
  • 1
  • 17
  • 36

1 Answers1

0

Restricting user may spoil the user exp,if you are sure that it wouldnt ruin the experience go ahead with this code--->

//this function will rotate you screen(cross browser!!!)
function rotate(el, degs) {
      iedegs = degs/90;
      if (iedegs < 0) iedegs += 4);
      transform = 'rotate('+degs+'deg)';
      iefilter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation='+iedegs+')';
      styles = {
        transform: transform,
        '-webkit-transform': transform,
        '-moz-transform': transform,
        '-o-transform': transform,
        filter: iefilter,
        '-ms-filter': iefilter
      };
      $(el).css(styles);
    }

//this will check your orientation and then take action as you desrired!!!
    $(window).bind('orientationchange resize', function(event){
      if(event.orientation) {
        if (event.orientation == 'landscape') {
          if (window.rotation == 90) {
            rotate(this, -90);
          } else {
            rotate(this, 90);
          }
        }
      });
HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87