How to hide link information at the bottom left/right of the browser on hover

后端 未结 4 822
予麋鹿
予麋鹿 2020-12-31 11:12

How can I create a link that doesn\'t show its information at the bottom left or right (this depends on the link\'s position) when you hovering a hyperlink? Lets say that we

相关标签:
4条回答
  • 2020-12-31 11:47

    It cannot be done with pure html and css. You would have to use javascript for this. Showing the link of an anchor tag is just how most browsers work. Also the user expects to be able to see where he will be redirected.

    But it can be done: you can avoid using an anchor tag. Then have another attribute hold the href - like "data-href". Then bind a click event on the a tag that redirects based on this attribute.

    I would however, not do this - as I am uncertain if crawlers would see the link.

    This is how it can be done, but note that snippets cannot redirect outside SO :)

    var aTags = document.querySelectorAll('span[data-href]');
    
    for(var i = 0; i < aTags.length; i++){
        var aTag = aTags[i];
        aTag.addEventListener('click', function(e){
            var ele = e.target;
            window.location.replace(ele.getAttribute('data-href'));
        });    
    }
    span[data-href]{
        cursor:pointer;
    }
    <span data-href="http://www.google.com">test</span>

    0 讨论(0)
  • 2020-12-31 11:58

    The stackoverflows Anybody can ask a question-Link is not a hyperlink. Its a HTML Element (in this case a li-Element):

    <li id="q">Anybody can ask a question
    </li>
    

    with the CSS cursor: pointer; and a click-Eventlistener.

    0 讨论(0)
  • 2020-12-31 12:07

    After digging even more deeper, I've found a more simpler and easier solution for it on this w3schools article and also with the help of this question in SO I could manage it to open on a new window:

    <button id="anchorID" >Go to page</button>
    
    $("#anchorID").click(function() {
        window.open(
        'http://www.w3schools.com',
        '_blank' // <- This makes it open in a new window.
        );
    });
    

    Jsfiddle live example: http://jsfiddle.net/6sLzghhm/

    0 讨论(0)
  • 2020-12-31 12:08

    Remove the href="whatever" from the link and open link by calling a function. This completely removes the link preview on the bottom left of the page.

    HTML-

    <a (click)="openUrl('https://google.com')">
    

    JS-

      openUrl(url: string): void {
        window.open(url, '_blank');
      }
    
    0 讨论(0)
提交回复
热议问题