Loading Image

Almost there...

Loading Image

Loading...

Detect Orientation of Device

This JavaScript function lets you detect the orientation of the device your website is browsed on. It does so by getting the devices screen height and width, and from there establishes if it is either Portrait or Landscape.
28 February 2017 - 10:00
Downloads: 459
Category: JavaScript
Detect Orientation of Device
Overview

This javascript function lets you detect the orientation of the device you website is browsed on. It does so by getting the devices screen height and width, and from there establishes if it is either Portrait or Landscape.

JavaScript Code:
<script type="text/javascript">
function codeAddress() {
	if(window.innerHeight > window.innerWidth){
		//Portrait
	}else{
		//Landscape
	}
}
window.onload = codeAddress;
</script>

<!-- CHECK IF DEVICE IS PORTRAIT -->
window.addEventListener("orientationchange", function() {
	if(window.innerHeight > window.innerWidth){
		//Portrait
	}else{
		//Landscape
	}
}, false);