Advertisement
plirof2

javascript script to go fullscreen browser

Feb 15th, 2024 (edited)
1,265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NOTE: RequestFullScreen needs to be bind to a user action (for security reasons)
  2. //OLDER iron/chrome : document.documentElement.webkitRequestFullScreen()
  3. var elem = document.documentElement;
  4. if (elem.webkitRequestFullScreen) {
  5.   elem.webkitRequestFullScreen();
  6. } else if (elem.mozRequestFullScreen) {
  7.   elem.mozRequestFullScreen();
  8. } else if (elem.requestFullScreen) {
  9.   elem.requestFullScreen();
  10. }
  11.  
  12. //Newer chrome : document.documentElement.requestFullscreen();
  13.  
  14. <script>
  15. /* Get the documentElement (<html>) to display the page in fullscreen */
  16. var elem = document.documentElement;
  17.  
  18. /* View in fullscreen */
  19. function openFullscreen() {
  20.   if (elem.requestFullscreen) {
  21.     elem.requestFullscreen();
  22.   } else if (elem.webkitRequestFullscreen) { /* Safari */
  23.     elem.webkitRequestFullscreen();
  24.   } else if (elem.msRequestFullscreen) { /* IE11 */
  25.     elem.msRequestFullscreen();
  26.   }
  27. }
  28.  
  29. /* Close fullscreen */
  30. function closeFullscreen() {
  31.   if (document.exitFullscreen) {
  32.     document.exitFullscreen();
  33.   } else if (document.webkitExitFullscreen) { /* Safari */
  34.     document.webkitExitFullscreen();
  35.   } else if (document.msExitFullscreen) { /* IE11 */
  36.     document.msExitFullscreen();
  37.   }
  38. }
  39. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement