adikahorvath
2/26/2014 - 9:23 AM

measure mobile / tablet device orientation

measure mobile / tablet device orientation

function scanOrientation() {
	var width = window.innerWidth;
	var height = window.innerHeight;
	
	if (width < height){
		// _gaq.push(['_trackEvent', 'Orientation', 'Portrait']);
		console.log("Portrait: " + width + "x" + height);
	}
	if (width > height){
		// _gaq.push(['_trackEvent', 'Orientation', 'Landscape']);
		console.log("Landscape: " + width + "x" + height);
	}
}


document.addEventListener("DOMContentLoaded", function() {
	scanOrientation();
}, false);

window.addEventListener("orientationchange", function() {
	// _gaq.push(['_trackEvent', 'Orientation', 'Changed']);
	scanOrientation();
}, false);