I want to log all clicks on a link.
I\'ve written a little logger, which can be called by an url (returns an empty page). This url is called with a jquery-ajax-metho
I think the reason FF is giving you poor results is because you're leaving the page before the action takes time to execute. As mhartman's link mentions if you use a target on your external link it should work fine. If you can't do that then you may have to wait for the log to complete, although you may see delays in navigation.
HTML code
Click
the
function loggClick(e) {
if (!e) e = window.event;
e.preventDefault(); // cancels the link
var theLink = this.href; // stores the link for later
$.ajax({
async: false,
type: "POST",
url: "Logger.ff", //dynamic url to logging action
data: {
sid: 'abc123' //random data
},
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
cache: false,
complete: function() {
// navigate when the log completes
this.location.href = theLink;
}
});
return true;
}
}