Skip to content

Instantly share code, notes, and snippets.

@Novout
Last active May 29, 2022 22:52
Show Gist options
  • Select an option

  • Save Novout/0fa1496cc1bca7863022bbcfdbcae100 to your computer and use it in GitHub Desktop.

Select an option

Save Novout/0fa1496cc1bca7863022bbcfdbcae100 to your computer and use it in GitHub Desktop.
Correct handle requestFullscreen() method
const fullscreen = () => {
window.document.exitFullscreen().catch(() => {
const target = window.document.querySelector('body')
target?.requestFullscreen()
})
}
// change the conventional global method
window.addEventListener('keypress', (e) => {
if(e.key === 'F11') {
e.preventDefault()
e.stopPropagation()
fullscreen()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment