Toggle fullscreen mode

JavaScript, Browser · Oct 19, 2020

Opens or closes an element in fullscreen mode.

  • Use Document.querySelector() and Element.requestFullscreen() to open the given element in fullscreen.
  • Use Document.exitFullscreen() to exit fullscreen mode.
  • Omit the second argument, el, to use body as the default element.
  • Omit the first element, mode, to open the element in fullscreen mode by default.
const fullscreen = (mode = true, el = 'body') =>
    ? document.querySelector(el).requestFullscreen()
    : document.exitFullscreen();
fullscreen(); // Opens `body` in fullscreen mode
fullscreen(false); // Exits fullscreen mode

More like this

  • Toggle class of HTML element

    Toggles a class for an HTML element.

    JavaScript, Browser · Oct 22, 2020

  • Render DOM element

    Renders the given DOM tree in the specified DOM element.

    JavaScript, Browser · Oct 13, 2021

  • Serialize form

    Encodes a set of form elements as a query string.

    JavaScript, Browser · Oct 22, 2020