Search code examples
cssvisited

Force link to look not visited using CSS


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.


Solution

  • 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;