使用this question中的一些代碼我設置了一些代碼來檢測Android設備何時被旋轉。它適用於asus tablet(4.0.3)和兩個模擬器(4.0.3和2.1),但對於點燃(2.3.4)和droidx(2.3.4),它會切換寬度和高度。在Android設備上使用javascript檢測方向
代碼:
<script type="text/javascript">
var supportsOrientationChange = "onorientationchange" in window,orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
alert("The rotation is " + window.orientation + " and the resolution is " + screen.width + " x " + screen.height);
modRule();
}, false);
</script>
從華碩平板
輸出保持它是什麼樣子的風景:
旋轉爲0,分辨率爲1280 x 800的
肖像
旋轉爲-90和分辨率是800×1280
從燒火輸出
景觀
旋轉是90和分辨率爲600 * 819
肖像:
旋轉爲0,分辨率爲1024×395
從droidx輸出
景觀:
旋轉是90和分辨率爲320x488
肖像:
旋轉爲0,分辨率爲569x239
有沒有辦法,我可以
a)使JavaScript的檢測是否應該使用,而不是寬度高度或寬度,而不是高度
或
b)使設備報告寬度和高度的正確值?