如何禁用或隐藏超链接的“在新标签页中打开”选项 [英] How to disable or hide the Open In New Tab option for hyperlinks

查看:453
本文介绍了如何禁用或隐藏超链接的“在新标签页中打开”选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在右键菜单中的超链接上,如何删除或隐藏在新标签页中打开在新窗口中打开选项?

On hyperlinks in the right click menu, how can I remove or hide the Open In New Tab and Open In New Window options?

例如

<a href="#" onclick="asd">foo</a>


推荐答案

不确定为什么要这样做但是可以通过将 href 移动到 data-href 属性来完成,然后删除 href 并添加一个点击处理程序。 onclick将读取 data-href 并重定向。

Not sure why you'd want to do this but it can be done by moving the href to a data-href attribute, then remove the href and add a click handler. The onclick will read the data-href and redirect.

演示

var links = document.getElementsByTagName("a");

for(var i=0; i<links.length; i++){
    links[i].setAttribute("data-href", links[i].getAttribute("href"));
    links[i].removeAttribute("href");
    links[i].onclick = function(){
        window.location = this.getAttribute("data-href");
    };
}

右键菜单显示:

这篇关于如何禁用或隐藏超链接的“在新标签页中打开”选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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