window.orientation属性已经被废弃,不再建议使用。如果需要检测设备的方向,请使用window.matchMedia("(orientation: portrait)")或window.matchMedia("(orientation: landscape)")。
如果你仍然需要兼容旧的浏览器,可以使用以下代码:
复制
var orientation = window.orientation || window.screen.orientation && window.screen.orientation.type || window.mozOrientation || window.msOrientation;
这个代码会优先使用window.orientation,如果不存在则检查window.screen.orientation.type,然后再检查window.mozOrientation和window.msOrientation。```
window.orientation兼容各种浏览器写法
于 2023-04-26 12:56:52 首次发布