Dove Man Dove Man - 1 year ago 114
HTML Question

Redirect on Key Press?

So I have a website and I am looking for a way to redirect a user to another webpage when they press the ESC key.

Answer Source

You can use the keydown event and capture the event.keyCode, and if it is === 27 (esc), you issue a redirect. Like so:

document.body.addEventListener("keydown", function (event) {
    if (event.keyCode === 27) {
        window.location.replace("/*your url here*/");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download