【发布时间】:2020-08-28 00:27:50
【问题描述】:
我正在关注ScreenOrientation.lock() 的文档,但我无法让它按我的意愿工作。
https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock
在 Chrome 桌面上调用 window.screen.orientation.lock("portrait"); 时,我收到错误 screen.orientation.lock() is not available on this device. 作为未捕获错误。有没有办法检查设备是否支持锁定?
我已经将"orientation":"portrait" 放入manifest.json,但这只是默认方向,不是锁定。
https://www.w3.org/TR/appmanifest/#orientation-member
旁注:
我在理解如何调用该方法时遇到了一些麻烦。如果有人发现此线程,则示例错误:
ScreenOrientation.prototype.lock("portrait");
window.ScreenOrientation.prototype.lock("portrait");
导致此异常:
未处理的拒绝(TypeError):无法执行“锁定” 'ScreenOrientation':非法调用
(ScreenOrientation as any).lock("portrait");
导致此异常:
TypeError: ScreenOrientation.lock 不是函数
【问题讨论】:
-
一个后备方法是捕获异常。没有严格回答“检测是否”的前手。
标签: javascript css typescript