简体   繁体   English

如何使用热键打开多个链接?

[英]How can I open multiple links using a hotkey?

I want to open multiple links using a hotkey on a web page. 我想使用网页上的热键打开多个链接。 For this I am using accesskey for hotkey mapping and the following code. 为此,我正在使用用于热键映射的accesskey和以下代码。

<a href="https://link1"
   onclick="window.open('link2'); window.open('link3'); return true;"
   accesskey="1">Some text</a>

The onclick event will not acknowledge when the element is accessed using accesskey (but tab to select and enter works). 当使用accesskey访问元素时, onclick事件不会确认(但可以选择并输入工程的选项卡)。 Is there another DOM event, or method which can accomplish the function of hotkey = 'open_multiple_windows'? 是否还有另一个DOM事件或可以完成hotkey ='open_multiple_windows'功能的方法?

I have tried to use onsubmit , onchange , oninput , onselect and onopen . 我曾尝试使用onsubmitonchangeoninputonselectonopen

<a href="#" onclick="window.open('https://google.com','_blank'); window.open('https://bing.com','_blank');" accesskey=1></a>

这段代码应该可以,但是可能会阻止多个页面(作为弹出窗口)

since you are using jQuery this can be achieved by capturing the key down or key up and trigger open in different tab or window, 由于您使用的是jQuery,因此可以通过捕获向下的键或向上的键并在其他标签或窗口中触发打开来实现,

$(document).keydown(function( event ) {
  if ( event.which == 13 ) {
    event.preventDefault();
    window.open('http://stackoverflow.com/', '_blank');
  }
});

This would open up stackoverflow into a new window when the user press on the ENTER key. 当用户按ENTER键时,这将打开stackoverflow进入新窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM