0
How can i get a url opens in a new tab by pressing a key on my keyboard?
I was trying with window.open but i got stuck when i try to use the keycode of the key that i want for example if i pressed y youtube opens or if a pressed g google opens in a new tab. That's what want to do but im lost on how to, i hope someone could help me. I was trying this window.addEventListener('keydown', function(e) {var link = document.querySelector('a[data- key="${e.keyCode}"]') --- to select the key if (!link) return; window.open }); this is how i think it could be but really i don't know
6 Réponses
+ 1
then you just need to check by :
document.addEventListener('keydown', function(event){
{
if(event.keycode == your key code) {
window.open("youtube.com")
}
}
0
I'd really apreciate any help. Thanks in advance
0
window.open("example.com")
0
yes i know that
window.open("example.com", "_blank", status=0);
but what i mean is doing it by pressing a specific key from my keyboard so at the time i press the "y" key the url opens youtube in a new tab
0
you need to know key code of Y letter
you can get it with this function:
document.addEventListener('keydown', function(event){ alert(event.keycode) }
0
thanks i"ll try that c: