Css history hack

Posted on October 19, 2009

Yes ok old, but I did not know about this, so I'll blog it! :P
Something I've heard about where I work, it is a way to check if the user visited a site. The limitation resides in the fact that the javascript code has to have a list to check, so you cannot just loop through one's browsing history.

Here's how it works. For each site create a link, then add it to the document's body and check its colour. So, based on the colour you get, you know if that site has been visited by the user.

This is the import part of the code, took from here:

for (var i = 0; i < websites.length; i++) {          
    var link = document.createElement("a");       
    link.id = "id" + i;       
    link.href = websites[i];       
    link.innerHTML = websites[i];              
    document.body.appendChild(link);       
    var color = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");       
    document.body.removeChild(link);             
     if (color == "rgb(0, 0, 255)") {           
         document.write('' + websites[i] + '');
    }
}

You can see here for an impressive example of this.

More on this:

Browse the archive

blog comments powered by Disqus