src/core/sensors.js
/**
 * Locks the screen orientation to the given orientation. It must go fullscreen first.
 * @param orientation  String, one of the values from 
 * https://w3c.github.io/screen-orientation/#screen-orientation-types-and-locks
 */
Locks the screen orientation to the given orientation. It must go fullscreen first.
Locks the screen orientation to the given orientation . It must go fullscreen first .
function lockScreenOrientation(orientation) {
    document.addEventListener('fullscreenerror', (event) => {
        console.error('Could not change to fullscreen');
        console.log(event);
    });
    if (!document.fullscreenElement && !document.mozFullScreenElement
            && !document.webkitFullscreenElement && !document.msFullscreenElement) {
        let de = document.documentElement;
        if (de.requestFullscreen) { de.requestFullscreen(); }
        else if (de.mozRequestFullScreen) { de.mozRequestFullScreen(); }
        else if (de.webkitRequestFullscreen) { de.webkitRequestFullscreen(); }
        else if (de.msRequestFullscreen) { de.msRequestFullscreen(); }
    }
    screen.orientation.lock(orientation)
    .then((success) => { console.log(success)},
          (failure) => { console.error("Could not lock screen orientation"); console.log(failure)});
}
function lockScreenOrientation ( orientation ) { document . addEventListener ( 'fullscreenerror' , ( event ) => { console . error ( 'Could not change to fullscreen' ) ; console . log ( event ) ; } ) ; if ( ! document . fullscreenElement && ! document . mozFullScreenElement && ! document . webkitFullscreenElement && ! document . msFullscreenElement ) { let de = document . documentElement ; if ( de . requestFullscreen ) { de . requestFullscreen ( ) ; } else if ( de . mozRequestFullScreen ) { de . mozRequestFullScreen ( ) ; } else if ( de . webkitRequestFullscreen ) { de . webkitRequestFullscreen ( ) ; } else if ( de . msRequestFullscreen ) { de . msRequestFullscreen ( ) ; } } screen . orientation . lock ( orientation ) . then ( ( success ) => { console . log ( success ) } , ( failure ) => { console . error ( "Could not lock screen orientation" ) ; console . log ( failure ) } ) ; }
Locks the screen orientation to the given orientation.
Locks the screen orientation to the given orientation .
// Code from https://code-boxx.com/lock-screen-orientation/