Randomize

Richard Tallent’s occasional blog

Detect the social sites your visitors use, but without JavaScript!

Aza came up with a cool use for a well-known browser trick.

I’ve adapted it to work without needing Javascript.

The trick used is that if you wrap an HTML anchor tag (link) inside another anchor, the inner link is the one that is followed, but the outer link is still rendered according to its own visited status. Example:

<style type="text/css">
a.testurl:link { display: none; }
a.testurl:visited { display: block; }
</style>
<a class="testurl" href="http://www.digg.com/">
<a href="http://digg.com/submit?url">dig me!</a></a>
<a class="testurl" href="http://www.slashdot.org/">
<a href="http://www.slashdot.org/blah">slashdot me!</a></a>
<a class="testurl" href="http://www.reddit.com/">
<a href="http://www.reddit.com/submitstoryurl">Reddit me!</a></a>

The link labels above could be logos, of course, not just text. If you use cache-suppression on those logo image files (via headers, adding the timecode to the end of the URLs, etc.), your server can even track which sites your users are using, by simply watching the hits on your server to those image files.

What if the user doesn’t actually ever visit the home page of these sites? Many people have some inner page bookmarked instead (a login page, a specific topic area, etc.).

SocialHistory.js attempts to work around this by having a list of common landing pages for each site–pretty good, but we can’t nest those in CSS (AND vs. OR logic), and creating a separate link for each might result in duplicate links for users who visit multiple tested URLs.

But there’s still a workaround! Just find an image, CSS, or Javascript file that most pages at the site refers to, and use that as the browser history test URL. Example:

<a class="testurl" href="http://digg.com/img/menu-current.gif">
<a class="submiturl" href="http://digg.com/submit?url">dig me!</a></a>

In this case, “menu-current.gif” is an image file used on EVERY page in Digg, so even if you never visit the home page, your browser will still display the inner Digg link if you’ve visited ANY page on Digg.


Share

comments powered by Disqus