views:

117

answers:

2

I just don't want the site change orientation when iPhone change orientation.

Is it possible?

+6  A: 

You can't prevent this via JavaScript, it's browser controlled...and really you'd be breaking the user's expectations of behavior if you could do this, which is hardly ever a good thing.

Also if you could, which orientation would the user be in? When they arrived on your site the phone could have been in either orientation.

Nick Craver
If you're creating a game or extremely specific interface, you should be able to prevent rotation.
Stefan Kendall
@Stefan - No, you shouldn't. If you're after a very specific display like this then write a native application, the browser should be the shape the user wants it, *exactly* like a desktop behaves. It's not *your* choice to make for the user. Also, is there something actually *wrong* with my answer? If you disagree with what Apple lets you do that's fine, but it doesn't make my answer any less accurate, you can't do this.
Nick Craver
No, you're wrong. The browser IS an application platform, whether your like it or not. As such, you should have control over interface locking, as well as probably other hardware specific features. That's why the HTML5 spec includes geolocation, among other things.Web applications CAN act like native, also, if you install to homescreen. It's silly if you limit a web app built specifically for the iPhone in this way.
Stefan Kendall
@Stefan - Geolocation again is a *user choice* they can choose to disable or enable the feature, your app can and should adapt. I agree pages can act like native applications in many respects, but controlling screen orientation isn't one of them. Also I don't believe my answer said the browser *wasn't* an application platform, I simply stated you can't do *this* in that platform...and you can't. So again I ask, what was actually wrong with the answer?
Nick Craver
Not only are you philosophically wrong, you're practically wrong.
Stefan Kendall
I agree with Nick, it's a browser...sure it is an application platform, but as with all platforms, you have to determine whether that platforms limitations will fit your needs
davidsleeps
See my answer. It's possible to keep a single orientation mode.
Stefan Kendall
@Stefan - The answer in your link *doesn't prevent rotation*, it adapts to it, which is *exactly* what I've said you should do, adapt to the platform the limitations you're on. I'm glad apple lets you apply different CSS in this case, but you're not actually *preventing or reversing* the rotation.
Nick Craver
You used "adapting" to mean "working around limitations". This is a dumb hack to prevent behavior which should exist. Apple IS wrong to not provide this feature.But hey, who needs copy/paste?
Stefan Kendall
@Stefan - I think you're *greatly* widening the scope of the question to fit your argument "what features *should* apple have included?" While that is a great discussion, it's not the question at hand. Should other desktop browsers support this when I rotate my monitor 90 degrees the same way? Why not? When you go into "things this *should* do" that's a *very* deep rabbit hole, and doesn't really help the OP.
Nick Craver
Agreed that at its core a browser is just a very sophisticated, interactive text reader. Praising it as an application platform has always irked me. A browser is still a passive consumption device that displays content. The content shouldn't have any power over the user or display device.
deceze
+2  A: 

See this answer for how to use CSS/JS to rotate the rendered display on orientation change. The idea is to capture the orientation event, and then force the display back to portrait/landscape.

http://stackoverflow.com/questions/1207008/how-do-i-lock-the-orientation-to-portrait-mode-in-a-iphone-web-application

Stefan Kendall