Home > Back-end >  Javascript: Open popup window in Chrome with hotkey
Javascript: Open popup window in Chrome with hotkey

Time:10-29

I am trying to write a window popup function, so whenever person types character v in Chrome, it will open popup. The following is not working, I type "v" on keyboard, and no popup window opens. How can I fix this? Using this in F12 Console to write the function.

function doc_keyUp(e) {
    if (e.keyCode == 86) {
       alert("Test!");
    }
}

Resource Hotkey: https://keycode.info/

CodePudding user response:

Try it:

window.addEventListener("keydown", e => {
    if ( e.keyCode == 86 ) {
        //window.open("url")
    }
});

CodePudding user response:

Use keyCode Search to get correct keyCode

demo page

window.addEventListener("keyup", function(e) {
    if ( e.keyCode == 86 ) {
        window.open('http://www.google.com','GoogleWindow', 'width=800, height=600');
    }
});
  • Related