Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to prevent iPhone/iPad orientation changing in the browser?

I've seen similar questions on this issue, but they are related to native apps. I build web apps for the iPhone/iPad that run in the browser (Safari).

I was wondering if there is a way to prevent orientation change in the browser, perhaps via some meta tag. I know of the viewport meta tag which allows you to specify scale and zooming capabilities, so figured maybe there is something similar for orientation.

I doubt it is possible, but I thought I'd just pop a question on here to see.

like image 340
BoomShaka Avatar asked May 05 '10 11:05

BoomShaka


People also ask

How do I lock orientation in Safari?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.

How do I lock screen rotation?

Whether you are holding your device upwards or sideways, swipe down from the top of the screen. Tap the Auto rotate icon to lock your device in your desired position.

Why do some websites not rotate on my iPad?

If the rotation lock icon does not appear on your screen and your iPad's native apps won't rotate, your iPad is most likely experiencing a software glitch. Turning the iPad off completely, then restarting it should fix the issue. If not, your software may be outdated.

What is portrait orientation lock?

Portrait Orientation icon. to lock or unlock screen portrait orientation. When the icon is highlighted in white, the screen is locked into portrait orientation mode. The Contol Center screen may vary slightly depending on the device model.


1 Answers

You can detect orientation changes with onorientationchange.

Javascript:

/*window.orientation returns a value that indicates whether iPhone is in portrait mode,    landscape mode*/
window.onorientationchange = function() {
var orientation = window.orientation;

switch(orientation) {
    case 0:
         //Portrait mode
    case 90: 
         // Landscape left
    case -90:
         //Landscape right
}

It's written in iPhone doc. Here from iPhone docs.

like image 153
medopal Avatar answered Oct 21 '22 08:10

medopal