The problem is that these people are just lazy:
<html>
<body>
<a href="http://pythonwise.blogspot.com"
onclick="jump(this, 1);">Pythonwise</a> knows.
</body>
<script src="jquery.js"></script>
<script>
function jump(url, value)
{
$.post("jump.cgi", {
url: url,
value: value
});
return true;
}
</script>
</html>
Notes:
7 comments:
If you're using jQuery, why set onClick in HTML?
Instead, you could just do
document.ready(
function() {
$('a').each(function() {
url = $(this).attr('href');
$(this).click(
function() {
$.post('jump.cgi',
{ 'url': url,
'value': x } );
} );
} );
} );
I agree, however my personal incline is to do as little as possible on the client side.
Also, your approach takes *all* links, while the common case will be just to take some of them.
Cool hack though ...
Of course the problem with either of these approaches is that if the user has javascript disabled, then everything still works fine for the user but the site loses the tracking they need/want. You could just as easily reverse the logic though and have the actual link href point at the jump counter and use javascript to show the jump target onmouseover of the link.
You are right, however I prefer that the user will "win" and the site will "loose" and not the other way.
If the user disables JS, then the onmouseover will not work.
Finally!
A post I can understand.
Happy passover,
the guy with the Coke.
Miki - yes, my example attaches click events to every link (actually to every anchor tag, which might be worse), but if you only want that behavior on some links, just use a more specific selector - change $('a') with $('a.outgoing') to only track clicks on links with the class="outgoing" attribute, or $('#blogroll a') to only track clicks on links in an element with the id "blogroll". Or use one of the more trickier CSS3 selectors that jQuery supports to apply the behavior only to link elements with an href attribute containing (or not containing specific text.
Post a Comment