Screen orientation on tablet error

I have a strange issue. I have an LG g700 tablet and I want to set the orientation locked. But when i test it on my nexus 5 it works well with the following code:

window.screen.orientation.lock("landscape")

But when i do the same code on my tablet it doesn't work and it gives an error like:

Uncaught (in promise) DOMException: The page needs to be fullscreen in order to call lockOrientation(). {message: "The page needs to be fullscreen in order to call lockOrientation().", name: "SecurityError", code: 18, INDEX_SIZE_ERR: 1, DOMSTRING_SIZE_ERR: 2…}code: 18message: "The page needs to be fullscreen in order to call lockOrientation()."name: "SecurityError"__proto__: DOMException

Is there an solution for this?

Answers:

Answer

This can be done only on full screen mode. So I suggest you add a timeout before calling screen.orientation just to make sure that full screen is active and ready.

if (document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen) {
   setTimeout(function(){
      window.screen.orientation.lock("landscape");
   }    , 200);
}

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.