-3

What I want to do is to close a webpage using the shortcut control + W.

Can I write a piece of code that will simulate the shortcut (control+W).

Umar
  • 1
  • 1
  • 4
  • Try this: https://stackoverflow.com/questions/7295508/javascript-capture-browser-shortcuts-ctrlt-n-w – Martin Oct 21 '21 at 11:24

1 Answers1

0

I think this is what you are looking for:

document.addEventListener('keydown', function(event) {
    if(event.key == "Control" && event.key == "w") {
        close();
    }
});
  • I don't think that event.key can ever be "Control" and "w" at the same time on a non-quantum computer. Also I think the OP wants to know how to "emit" that event instead of reacting to it. – lupz Oct 21 '21 at 11:47