15

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 have a link like this:

 <a href="/users">Users</a>

and we want to hide its information or more precisely its hyperlink information that's displayed at the bottom left corner of the browser, like the example on the image below:

Now, I know this is possible because Stack Exchange network sites itself uses this for the "Welcome Banner" displayed on the front page for the very first time you visit each site.

If you hover any of the links:

  • Anybody can ask a question

  • Anybody can answer

  • The best answers are voted up and rise to the top

You'll see that no hyperlink information is displayed. Check out image below to see "Welcome Banner"

Chun
  • 2,230
  • 5
  • 24
  • 46

7 Answers7

10

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>
Peter Rasmussen
  • 16,474
  • 7
  • 46
  • 63
  • Crawlers would definitely not see the link. – pstenstrm May 23 '15 at 08:57
  • Not a big deal but since we are micking a href (but instead not making it show the link at the bottom left), It's better to use `window.location.href = ele.getAttribute('data-href')` instead of `window.location.replace(ele.getAttribute('data-href'))` because using `location.replace` means the person will not be able to go back to where they were after clicking the back button because the history is replaced by the new link but not also stored as href works. Also I think it's better, and less code to use `forEach` instead of a full for-loop. – Ecks Dee Oct 04 '20 at 18:14
2

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/

Community
  • 1
  • 1
Chun
  • 2,230
  • 5
  • 24
  • 46
2

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');
  }
1

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.

nbar
  • 6,028
  • 2
  • 24
  • 65
0

The easiest answer is just use-

<p onclick="window.open('Your Link')">Blah Blah Blah</p>

Easy!

You can also open more links at a time-

HTML:

<p onclick="OpenTwoLinks()">Google And StackOverFlow</p>

Javascript:

function OpenTwoLinks() {
   
  window.open('https://google.com');
   
  window.open('https://stackoverflow.com');
}
0

for hide the information use this code:

<button onclick="window.location.replace("https://yourdomain.com/path")"></button>

location.window.replace for replace the current link to another link

0

Try:

<a onclick="window.location = '/users'">Users</a>
User5486
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '23 at 00:12