Next page "spacebar button" press

86 Views Asked by At

I need the JavaScript to go to 'pag2' when I press spacebar, but it does nothing, there isn't anything on 'pag1' or 'pag2' (the files) `

document.body.onkeyup = function(e) {
  if (e.key == " " ||
      e.code == "Space" ||      
      e.keyCode == 32      
  ) {
    window.location.href="pag2.html"
  }
}

`

I've tried changing the href to replace, but it didn't work. You should know what I was expecting, but if you didn't, here's what I was expecting: It to take me to file 'pag2'

0

There are 0 best solutions below