弃用
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)

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
unlockOrientation Chrome 38 Edge 12 Prefixed
12 Prefixed
Prefixed Implemented with the vendor prefix: ms
Firefox Yes Prefixed
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 11 Prefixed
11 Prefixed
Prefixed Implemented with the vendor prefix: ms
Opera Yes Safari No WebView Android 38 Chrome Android 38 Firefox Android Yes Prefixed
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Yes Safari iOS No Samsung Internet Android 3.0

图例

完整支持

完整支持

不支持

不支持

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. Screen
  2. 特性
    1. availHeight
    2. availLeft
    3. availTop
    4. availWidth
    5. colorDepth
    6. height
    7. left
    8. mozBrightness
    9. mozEnabled
    10. onorientationchange
    11. orientation
    12. pixelDepth
    13. top
    14. width
  3. 方法
    1. lockOrientation()
    2. unlockOrientation()
  4. 继承:
    1. EventTarget
  5. Related pages for Screen Orientation API
    1. Screen.orientation
    2. ScreenOrientation

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1