Force link to look not visited using CSS

453 Views Asked by At

Is there a way to use CSS to make a given link appear as it is not visited, even if it has already been visited?

I know you can do this by explicitly setting the same color for the visited and non-visited links. But is it possible to do this without hardcoding the color of the visited links? Just telling the CSS to color them using the same color as the non-visited links, whatever that may be.

The reason for this is that I want to Rickroll a friend.

2

There are 2 best solutions below

0
On BEST ANSWER

One solution using Javascript is to get the color using the getComputedStyle function. This takes advantage of the fact that the getComputedStyle function always pretends that the link is colored as if it hadn't been visited (as an anti-fingerprinting measure).

// Set the colot of a link to the color of a non-visited link
var link = document.getElementById("TheID");
var color = window.getComputedStyle(link).getPropertyValue("color");
link.style.color = color;
8
On

You can leverage the inherit property:

a:visited {
  color: inherit;
}

Another option is to use !important:

a {
  color: red !important;  
}