0

my css file has this

a:visited
{
color:red;
}

and my html page has this

<body>
<a href="http://www.w3schools.com">W3Sschools</a>
<div></div>
<a href="http://www.google.com">Google</a>
<div></div>
<a href="http://www.wikipedia.org">Wikipedia</a>
<div></div>
<script>
if($("a:visited").length){
$("a").next().html("this link is visited");
}
</script>
</body>

but it doesn't work .. so i tried another alternative in the script area

<script>
if($("a").css("color","red")){
$("a").next().html("this link is visited");
}
</script>

and it turns all my links in red even if they are not visited what's wrong with this !

user1283226
  • 17
  • 1
  • 9
  • Theoretically you *think* it should work. However, it won't work. Never. You can't distinguish whether the link was visited by the CSS colour style. – VisioN Nov 28 '12 at 19:45
  • Does it work if you visit a link then refresh the page with the code on? I can't see how that script is called, but if it only runs on load then, at teh time, the link wouldn't have been visited yet (long shot) – Martin Lyne Nov 28 '12 at 19:46
  • Also check out http://stackoverflow.com/questions/1210871/use-jquery-to-select-visited-links – Martin Lyne Nov 28 '12 at 19:48
  • Martin Lyne .. the script isn't called by anything, and there's no event to trigger the script .. it runs automatically onload of the page when i visit a link .. the browser can distinguish if it's visited or not because it's stored in the history and the cache .. cookies (that why the visited selector in css exist) and after clicking a link .. i referch my page and the script doesn't work ! – user1283226 Nov 28 '12 at 19:54
  • i've don't my homework .. already seen that question but it wasn't useful to me .. but thanks – user1283226 Nov 28 '12 at 19:56

1 Answers1

4

This was a security flaw that has been fixed with modern browsers. It had been possible to spit out huge amounts of link lists in a hidden div and determine, if the user visited them or not.

So this way, you could practically sniff the users history, if you only check enough links. Neither checking for :visited, nor using the color check will do. Think of another way to do this without relying on :visited.

David Müller
  • 5,291
  • 2
  • 29
  • 33