Prevent orientation change in iOS Safari

前端 未结 9 1553
死守一世寂寞
死守一世寂寞 2020-11-28 02:56

Is it possible to avoid transition to landscape view in Safari for iOS when the device is rotated?

iOS Safari has the \"orentationchange\" event, I tried to intercep

9条回答
  •  清歌不尽
    2020-11-28 03:41

    Maybe in a new future...

    As for May 2015,

    there is an experimental functionality that does that. But it only works on Firefox 18+, IE11+, and Chrome 38+.

    However, it does not work on Opera or Safari yet.

    https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation#Browser_compatibility

    Here is the current code for the compatible browsers:

    var lockOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;
    
    lockOrientation("landscape-primary");
    

提交回复
热议问题