4.1 Locking the screen orientation
The steps for locking the screen orientation are as follows:
If the user agent does not allow the current browsing context to lock the screen orientation, the steps must stop here and return false. For example, a user agent might only allow browsing context in a fullscreen state to lock the screen orientation or browsing context with elevated privileges.
Let orientations be the list of locking orientations.
For each orientation in the orientations list, run the following sub steps:
If orientation isn't part of the allowed orientations, the steps must stop here and return false.
If orientation is portrait or landscape the value must be removed from orientations and every allowed orientations it is representing must be inserted in orientations.
If orientations isn't a supported orientations set, the steps must stop here and return false.
Return true and run the remaining steps asynchronously.
The user agent must lock the orientation to orientations.
// 强制竖屏
window.screen.lockOrientation([“portrait-primary”,“portrait-secondary”]);
// 强制横屏
window.screen.lockOrientation([“landscape-primary”,“landscape-secondary”]);
// 取消强制
window.screen.unlockOrientation();
PS:由于腾讯出品,不保证w3c好用;