关于方向改变的JavaScript警报在Android上不断刷新
当移动设备的方向发生更改时,此代码将创建警报。它在我的iPhone上运行良好,但在我的Android上,该警报持续触发,有效地使页面无法运行。代码在dom就绪的环境下运行关于方向改变的JavaScript警报在Android上不断刷新,javascript,android,device-orientation,Javascript,Android,Device Orientation,当移动设备的方向发生更改时,此代码将创建警报。它在我的iPhone上运行良好,但在我的Android上,该警报持续触发,有效地使页面无法运行。代码在dom就绪的环境下运行 function orientation() { alert('orientation change'); // return false; } window.onorientationchange = orientation; 有人知道为什么会这样吗?如果有一个解决方案使用它,我会使用jQuery为
function orientation() {
alert('orientation change');
// return false;
}
window.onorientationchange = orientation;
有人知道为什么会这样吗?如果有一个解决方案使用它,我会使用jQuery为这个网站。谢谢
更新-此代码执行完全相同的操作:
var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
alert ('orientation changed');
}, false);
你试过返回
false
?我试过在没有注释的情况下添加它(见我更新的问题),但我得到了相同的问题。