HTML DOM document visibilityState Property

The visibilityState property returns the visibility of the document. This is a read-only property.

Syntax:

var vis = document.visibilityState;

Return Value:

  • visible: When page content may be visible to user.
  • hidden: When page content is not visible to user.
  • prerender: when document is being prerendered and is not visible to user.

Example:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <h1>GeeksforGeeks</h1>
      
    <button onclick="get()">
        Get visibility
    </button>
  
    <script type="text/javascript">
        function get() {
            var m = document.visibilityState;
            console.log(m);
        }
    </script>
</body>
  
</html>

chevron_right


Output:



Before Click the Button:

After Click the Button:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.