Can I determine if a device is in portrait or landscape mode using jquery?

B. Clay Shannon picture B. Clay Shannon · Apr 12, 2013 · Viewed 12.8k times · Source

I want to conditionally alter what the user sees on the photo gallery web site I'm going to create based on if the device being used to view the site is in portrait/vertical vs. landscape/horizontal mode/orientation. Is this possible?

Answer

Abbas picture Abbas · Apr 12, 2013

Try the orientationchange event handler, something like this:

$(window).bind("orientationchange", function(evt){
    alert(evt.orientation);
});

Here's the jQuery Mobile entry on detecting and firing the orientationchange event.