How to Exit Fullscreen in JavaScript?

Estimated read time 1 min read

To exit fullscreen mode in JavaScript, you can use the document.exitFullscreen() method. This method is available on the document object and can be called when your application is in fullscreen mode.

Here’s an example of how to exit fullscreen mode using JavaScript:

// check if the document is currently in fullscreen mode
if (document.fullscreenElement) {
  // exit fullscreen mode
  document.exitFullscreen();
}

This code checks whether the fullscreenElement property of the document object is set, indicating that the document is currently in fullscreen mode. If it is, the document.exitFullscreen() method is called to exit fullscreen mode.

It’s worth noting that document.exitFullscreen() is a standard method that is supported by most modern browsers. However, older browsers may require a different approach to exiting fullscreen mode. For example, some older versions of Internet Explorer use the document.msExitFullscreen() method instead. Therefore, you may need to check which method is supported by the user’s browser and adjust your code accordingly.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply