How do I make a URL open when the person presses a certain key?

Asked

Viewed 35 times

-2

<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <link rel="icon" a href="https://is.gd/DhDDsG">
<script>
var titulo = "- teste -"
var titulo = titulo + "          " 
i = "0"
var tmptitulo = "" 
var velocidade = "50"
const scrollTitulo = () => {
    if (!document.all && !document.getElementById)
        return
    document.title = tmptitulo + titulo.charAt(i)
    tmptitulo = tmptitulo + titulo.charAt(i)
    i++
    if (i == titulo.length)
    {
        i = "0"
        tmptitulo = ""
    }
    setTimeout("scrollTitulo()", 35)
}
window.onload = scrollTitulo
</script>
</head>
<body>

</body>
</html>

1 answer

1

If you want to use only HTML it is possible using accesskey, but in this case it is necessary to tighten the alt, as alt+s would be:

<a href="https://google.com" rel="noopener noreferer" target="_blank" accesskey="s">
                                                                       ^^^^^^^^^^^^

However, if you just want to click s (or any other key), without the alt, should use JS, using a simple Eventlistener. You can test below an example, click "s" and a page will open.

window.document.addEventListener("keydown", function(e){
  if (e.key != "s") {
    return
  }

  window.open("https://answall.com", "_self");
})

The keydown will be triggered whenever a key is pressed. So if the key is equal to s it will open the page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.