views:

954

answers:

4

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.

+1  A: 

Yes actually you can.

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 somewhere in iPhone doc, but I can't find it :).

UPDATE
Here from iPhone docs

medopal
Thanks medopal, but I already know it can be detected. My question was weather it could be prevented.
BoomShaka
+1  A: 

It does not appear to be possible to prevent orientation change, but you can detect it with the code mentioned above.

If you want to prevent orientation change it appears as though you'll need to build a native app using WebKit which quashes the event.

Brian Cully
A: 

why can't you just put a event.preventDefault() inside the function?

Michael.G.Dupee
A: 

You could be really tricky and rotate the body of the website to counteract the orientation change if nothing else works...

Ian Storm Taylor