通过按住链接禁用“打开新窗口”或“新建选项卡” [英] Disable Opening New Window or New Tab by holding down on a link

查看:66
本文介绍了通过按住链接禁用“打开新窗口”或“新建选项卡”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想感谢那些正在阅读这个和你的时间的人们。让我们直接讨论这个话题!

I want to thanks those who are currently reading this and for your time. Let's go straight to the topic!

我目前正在尝试禁用一个功能,用户无法通过按住来打开指向新窗口或标签的链接在一个链接上。

I am currently trying to disable a feature where a user should not be able to open a link to a new window or tab by holding down on a link.

任何建议或解答来解决这个问题,谢谢,
再次感谢!

Any suggestions or answers to approach this problem is appreciated, Thanks again!

推荐答案

您可以将事件处理程序绑定到所需的链接元素,并使用jQuery的 .preventDefault()方法取消链接到任何地方。你的代码看起来像这样:

You could bind an event handler to the desired link element and use jQuery's .preventDefault() method to cancel the link going anywhere. Your code would look something like this:

$('a').click(function(event){
  event.preventDefault();
});

这篇关于通过按住链接禁用“打开新窗口”或“新建选项卡”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆