Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

screen orientation lock

Is there a way to lock the display of a website in portrait mode, specifically for mobile devices? I read on the Mozilla Developer Network site that ScreenOrientation.lock("portrait") works in some commonly used browsers like Chrome and Firefox, but not Safari or IE. Thanks.

1 Answer

Steven Parker
Steven Parker
230,231 Points

Unless I'm missing something, you answered your own question. :wink:

For other browsers, Safari and Internet Explorer, is there not a standard way to lock the orientation? Is there a resource you'd recommend for this problem.

Steven Parker
Steven Parker
230,231 Points

Mozilla is my "go to" resource, so if they say that feature is not supported on those, I'd believe it.

And I seriously doubt we'll see anything new added to IE from this point.

You might, however, be able to sense the orientation with a media query and do something like blank the screen to coerce the user to keep the screen oriented correctly.

Steven Parker
Steven Parker
230,231 Points

I had a funny idea .. instead of blanking the screen, overlay an image of an arrow with the legend "this end up" :arrow_up: