Skip to content

Instantly share code, notes, and snippets.

@TakayoshiKochi
Last active June 7, 2021 14:52
Show Gist options
  • Save TakayoshiKochi/0f658e372a1d382523bd to your computer and use it in GitHub Desktop.
Save TakayoshiKochi/0f658e372a1d382523bd to your computer and use it in GitHub Desktop.
document.documentElement.focus()

http://crbug.com/467043

IE11:
  (default)
  document.body.tabIndex = 0
  document.head.tabIndex = 0
  document.documentElement.tabIndex = 0
  
  document.body.focus() -> work (regardless of tabIndex)
  document.documentElement.focus() -> work (regardless of tabIndex)
  document.head.focus() -> doesn't work (regardless of tabIndex)
Chrome44:
  (default)
  document.body.tabIndex = -1
  document.head.tabIndex = -1
  document.documentElement.tabIndex = -1

  document.body.focus() -> work (when tabindex != -1)
  document.documentElement.focus() -> work (tabindex != -1)
  document.head.focus() -> doesn't work (regardless of tabIndex)
Firefox39:
  (default)
  document.body.tabIndex = -1
  document.head.tabIndex = -1
  document.documentElement.tabIndex = -1

  document.body.focus() -> work (when tabIndex != -1)
  document.documentElement.focus() -> work (regardless of tabIndex)
  document.head.focus() -> doesn't work (regardless of tabIndex)
@CFarhad
Copy link

CFarhad commented Jun 7, 2021

Noiceeeee🎈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment