Detecting orientation changes on mobile devices

Simple way to detect orientation changes and positions.
JavaScript


<script language=\"JavaScript\" type=\"text/javascript\">
window.addEventListener('orientationchange', handleOrientation, false);
	function handleOrientation() {
		if (orientation == 0) {
  			//portraitMode
			alert('portrait1');
		} else if (orientation == 90) {
  			//landscapeMode
			alert('landscape1');
		} else if (orientation == -90) {
  			//landscapeMode
			alert('landscape2');
		} else if (orientation == 180) {
  			//portraitMode
			alert('portrait2');
		} else {
			
		}
}
</script>

Posted by fbrefere001 on Saturday March 22, 2014