【问题标题】:Open new tab with mouse weel and onclick event使用鼠标滚轮和 onclick 事件打开新选项卡
【发布时间】:2019-08-24 21:16:25
【问题描述】:

在新标签页中打开链接

<a href="mypage.php" target="_blank">My text</a>

使用javascript

<script type="text/javascript">
 function openLink(){
    window.location = 'my_page.php';
 }
</script>

<span onclick="openLink()">My text</span>

如何在不使用“a”标签的情况下使用 CTRL+Click使用鼠标滚轮单击 在新选项卡中打开链接?

【问题讨论】:

  • 到目前为止你有什么尝试?
  • 不使用哪个标签?

标签: javascript hyperlink onclick tags


【解决方案1】:

您需要检查事件对象的buttonctrlKey 属性并在条件中使用

document.querySelector('button').addEventListener('click', function(evt){
   console.log('CTRL key : ', evt.ctrlKey, '  Button : ',  evt.button);  
})
<button>
Click me
</button>

【讨论】:

    猜你喜欢
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多