Skip to content
Advertisement

Force “landscape” orientation mode

I’m trying to force the “landscape” mode for my application because my application is absolutely not designed for the “portrait” mode. How can I do that?

Advertisement

Answer

It is now possible with the HTML5 webapp manifest. See below.


Original answer:

You can’t lock a website or a web application in a specific orientation. It goes against the natural behaviour of the device.

You can detect the device orientation with CSS3 media queries like this:

JavaScript

Or by binding a JavaScript orientation change event like this:

JavaScript

Update on November 12, 2014: It is now possible with the HTML5 webapp manifest.

As explained on html5rocks.com, you can now force the orientation mode using a manifest.json file.

You need to include those line into the json file:

JavaScript

And you need to include the manifest into your html file like this:

JavaScript

Not exactly sure what the support is on the webapp manifest for locking orientation mode, but Chrome is definitely there. Will update when I have the info.

Advertisement