I have a HTML5 page which determines whether the device is "Portrait" mode or in "Landscape" .
Below is the code i have alerted the orientation . Sometimes when i turn from landscape to portrait it still alerts as landscape and the co ordinates i check are shown as wrong . The test device is Google Nexus
Tablet Google Nexus 7 Andriod version 4.2.2 Chrome App version:35.0.1916.141 OS Andriod 4.4.2;Nexus 7 Build/KOT49H Javascript version: V8 3.25.28.18
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="page">
</div>
</body>
</html>
<script type="text/javascript">
function pageSetter() {
if (window.matchMedia("(orientation: portrait)").matches) {
// you're in PORTRAIT mode
alert('Portrait');
}
if (window.matchMedia("(orientation: landscape)").matches) {
// you're in LANDSCAPE mode
alert('LANDSCAPE');
}
}
pageSetter();
window.addEventListener("orientationchange", function () {
pageSetter();
}, false)
</script>