I would like to get the color of a link on my page with jquery. To be blunt, I want to track a visitor to my page to see if they've been to another website, and then make inferences based on the websites they've visited.
The idea is this: I have a link to, say, profootballtalk.com. If they've visited that site, the link should appear red through the use of the :active pseudoclass. If not, it's blue. Then I use jquery to get the css("color") of the link element, telling me they've been to that site if it returns "red".
So I set up a simple html page, and guess what... It says the link is blue every time, even when it's red. Does anyone know what's going on? I wouldn't think this would fall under the usual "jquery doesn't support pseudoclasses" answer, since it really has to do only with grabbing the rendered color of the element.
Here is my entire html page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
a:visited {
color:red;
}
</style>
</head>
<body>
<a href="http://www.w3schools.com/css/css_pseudo_classes.asp">Linkitylinklinklink</a>
<a id="thisguy" href="http://whatscookinerndog.blogspot.com/2010/07/casa-de-luz-sun-cheese.html">facebook</a>
<script>
$(document).ready(function(){
var color = $("#thisguy").css("color");
alert(color);
});
</script>
</body>
</html>
This is not possible any more due to security features in modern browsers e.g. FireFox: http://hacks.mozilla.org/2010/03/privacy-related-changes-coming-to-css-vistited/
You will have to use something else like HTML5 localStorage, cookies or server-side storage to remember your users' movements.