Block Rotation Smartphone


(Marco) #1

Hello
I can block the smartphone’s rotation on portrait or landscape with a script when the file is displayed on the system browser?
thank you


#2

You can’t (and really shouldn’t ) block the rotation. But why not detect the orientation and display a message asking the user to use a certain orientation.

if (window.innerHeight < window.innerWidth) { // portrait orientation
    // show a message that asks the user to use landscape mode
    myElement = document.getElementById('ELEMENT_ID')
    myElement.innerHTML = "Please use Landscape Orientation";
}

How to ask user to change orientation to portrait if he/she rotates phone to landscape mode
#3

Hello and thanks for sharing this technique. It works if the phone is already in the orientation but does not work if the orientation is switched after the scene was loaded. We also wanted the message to go away when the user rotated the orientation back to normal again. This again is not possible because this technique does not really listen for orientation change. I am using this script in scene/layout load.

I have posted my issue in another post and would appreciate if you reply there: