Disable Opening New Window or New Tab by holding down on a link

前端 未结 4 712

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 sho

4条回答
  •  野的像风
    2021-01-19 07:25

    CSS:

    a{
       color: blue;
       cursor: pointer;
       text-decoration: underline;
     }
    

    Script:

    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");
        };
    }
    

提交回复
热议问题