HTML DOM fullscreenEnabled() method


The HTML DOM fullscreenEnabled() method is used for specifying if the fullscreen mode is available or not for the current document. Its return type is boolean and is a read-only property. True is returned if the fullscreen mode is available otherwise it returns false. Different prefixes are used to make it work with your browser.

Syntax

Following is the syntax for fullscreenEnabled() method −

document.fullscreenEnabled()

Let us look at an example for the fullscreenEnabled() method −

Note − You will need to use your browser prefix for fullscreenEnabled() method to work. Check the note at the last to have your browser specific prefix.

Example

Let us see an example −

<!DOCTYPE html>
<html>
<body>
<h1>fullscreenEnabled() method</h1>
<p>Click the below button to know if this document can be viewed in full screen mode or not</p>
<button onclick="EnableFullScreen();">CHECK</button>
<p id="Sample"></p>
<script>
   function EnableFullScreen() {
      var FullS=(document.fullscreenEnabled || /* Standard syntax */
      document.webkitFullscreenEnabled) /* Chrome, Safari and Opera */
      if(FullS==true)
         document.getElementById("Sample").innerHTML="This document can be viewed in fullscreen mode.";
      else
         document.getElementById("Sample").innerHTML="This document cannot be viewed in fullscreen mode.";
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking the CHECK button −

In the above example −

We have first created a button CHECK that will execute the EnableFullScreen() method on being clicked by the user.

<button onclick="EnableFullScreen();">CHECK</button>

The EnableFullScreen() function gets the document.FullScreenEnabled property value and assigns to variable FullS. The return value can either be true or false. It is then displayed in the paragraph with id “Sample” using its innerHTML property.

function EnableFullScreen() {
   var FullS=(document.fullscreenEnabled || /* Standard syntax */
   document.webkitFullscreenEnabled) /* Chrome, Safari and Opera */
   if(FullS==true)
      document.getElementById("Sample").innerHTML="This document can be viewed in fullscreen mode.";
   else
      document.getElementById("Sample").innerHTML="This document cannot be viewed in fullscreen mode.";
}

Note − We have specified the fullscreenEnabled() standard syntax and for Chrome, Safari and Opera browsers. Use the below prefixes if you use any other browser.

  • Firefox: document.mozFullScreenEnabled
  • IE/Edge: document.msFullscreenEnabled

Updated on: 20-Aug-2019

47 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements