views:

121

answers:

6

Hi, I'd like to know if there is a way to know if a link has already been opened. In firefox, the color of a link changes once you clicked it, so I guess it's possible.

Edit : This is for a firefox extension, so I can't change the HTML or CSS file.

Thanks :)

+1  A: 

Indeed, it is possible.

One way is to have different css classes:

a:visited { color : red; }
a { color : orange; }

Then detect that (in JavaScript).

Noon Silk
Unfortunatly, I can't change the CSS (as I said, it's for a Firefox plugin, and I'm not the owner of the internet :) ).
gramm
gramm: I haven't written a FF plugin but I suspect you can either insert some default/overwriting CSS with it, and/or, apply this to all elements on the page and then check for it.
Noon Silk
+1  A: 

We have a similar question. Check out using javascript to mark a link as visited. Got this while googling for an answer to your question ;-)

Shoban
A: 

You could specify different colors for unvisited (:link) and visited links (:visited) and check if the current color of your link has the visited’s one.

Gumbo
+1  A: 

If you don't want the links to have different colours, you can also apply some CSS that will turn out invisible

a:visited { padding-left: 1px; margin-left: -1px; }
a { padding-left: 2px; margin-left: -2px; }
Bart van Heukelom
A: 

Unfortunately it is possible to see what links were visited. I am saying unfortunately as it is considered a privacy violation. A while ago I came across this blog post Spyjax – Your browser history is not private! which describes this.

kristof
+1  A: 

You could use the querySelector function introduced in Firefox 3.5:

var vLinks = document.querySelector("a:visited");
for (var i=0, l; l = vLinks[i]; i++)
    alert(l.href);

https://developer.mozilla.org/En/DOM/Document.querySelector

I've never coded a Firefox extension though, so I'm not sure exactly how to access the currently loaded document.

Andy E