Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  62] [ 1]  / answers: 1 / hits: 174213  / 12 Years ago, wed, january 16, 2013, 12:00:00

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?


More From » css

 Answers
100

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:



@media screen and (orientation:portrait) {
// CSS applied when the device is in portrait mode
}

@media screen and (orientation:landscape) {
// CSS applied when the device is in landscape mode
}


Or by binding a JavaScript orientation change event like this:



document.addEventListener(orientationchange, function(event){
switch(window.orientation)
{
case -90: case 90:
/* Device is in landscape mode */
break;
default:
/* Device is in portrait mode */
}
});





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:



{
display: standalone, /* Could be fullscreen, standalone, minimal-ui, or browser */
orientation: landscape, /* Could be landscape or portrait */
...
}


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



<link rel=manifest href=manifest.json>


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.


[#80827] Tuesday, January 15, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayaw

Total Points: 749
Total Questions: 88
Total Answers: 86

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
tayaw questions
;