Detect orientation change on mobile devices

Mobile devices have two type of layout view, one is portrait and other one is landscape view. So for displaying our web page in both view, we need to programmatically make some changes. There are some ways to know when page view is changed. So let’s check out how we can detect orientation change on mobile devices.

orientationchange Event

The orientationchange event is triggered when the user rotates the mobile device vertically or horizontally.

Note: orientationchange event occures only on mobile, tablet and ipad device or a mobile emulator.

Syntax

function(event) : Required. function to run when the orientationchange event occurs.

the window.orientation property may provide the values:
0 – means portrait view
-90 – means a the device is landscape rotated to the right
90 – means the device is landscape rotated to the left
180 – means the device is portrait in opposite side


You may also interested inΒ iPad/iPhone detection using JavaScript

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.