Skip to content Skip to sidebar Skip to footer

How To Reset Css (a:visited{color:green}) When Refresh Browser Address Bar

I have successfully tested visited link effect on a tag for XHTML document. But those visited link highlight with green color could not removed when I refresh the address bar on my

Solution 1:

A "visited" link, i.e. one that gets picked up by the :visited pseudo-class, is one that is in the browser's history. So, the only way to turn those links back into non-visited links is to remove them from the browser's history.

Incidentally you don't need your a:link definition. :link is for highlighting non-visited links. Seeing as you have a base definition for a and a definition for a:visited, your a:link is redundant.

Here, however, is a proposed solution intended to defend against an attacker discovering a user's browser history by using getComputedClass to reveal all visited links in a page:

http://dbaron.org/mozilla/visited-privacy

(Almost certainly what you are looking for, but it's useful reading on the mechanics of :visited nonetheless)

Solution 2:

One solution is to add a randomizer to the end of href attributes of you link on page load. This way, when your page reloads, the link href is different since it has a new random value at the end.

// lets say, this is your linkvar link = document.getElementById('foo');

// suffix a randomizer to the href attributevar rand = Math.floor(Math.random() * 1000);
var href = link.getAttribute('href');
link.setAttribute('href', href + (href.indexOf('?') === -1 ? '?' : '&') + '_=' + rand);

Note: This will be useful only if the link opens in another tab/window or if it is an in-page link. Otherwise, clicking the link anyway takes the user to another page.

Solution 3:

In order to get rid of different color of a:visited, i use this:

a:visited {
    color: inherit;
} 

If this was asked.

Post a Comment for "How To Reset Css (a:visited{color:green}) When Refresh Browser Address Bar"