弃用
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the
兼容性表格
at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Screen.unlockOrientation()
method removes all the previous screen locks set by the page/app. The
ScreenOrientation.unlock()
method should be used instead.
注意: This method only works for installed Web apps or for Web pages in full-screen mode .
var unlocked = window.screen.unlockOrientation();
返回
true
if the orientation was successfully unlocked or
false
if the orientation couldn't be unlocked.
var unlockOrientation = screen.unlockOrientation || screen.mozUnlockOrientation || screen.msUnlockOrientation || (screen.orientation && screen.orientation.unlock);
if (unlockOrientation()) {
// orientation was unlocked
} else {
// orientation unlock failed
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Screen Orientation API
The definition of 'lockOrientation()' in that specification. |
工作草案 | Initial definition (Not present in the draft anymore) |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
unlockOrientation
|
Chrome 38 |
Edge
12
Prefixed
|
Firefox
Yes
Prefixed
|
IE
11
Prefixed
|
Opera Yes | Safari No | WebView Android 38 | Chrome Android 38 |
Firefox Android
Yes
Prefixed
|
Opera Android Yes | Safari iOS No | Samsung Internet Android 3.0 |
完整支持
不支持
要求使用供应商前缀或不同名称。
Screen
lockOrientation()
unlockOrientation()