Chapter 2: Pre-Ajax JavaScript Communications Techniques 53
PART I
before sending them to the site in question. This approach is problematic both because it is
dependent on the state of the current server to bounce the user and because it exposes the
tracking mechanism to the user in the status bar. Users who see such tracking is occurring
might alter their behavior or avoid the link altogether. To combat this, many sites (including
some famous search engines) use a JavaScript tracking technique instead that employs the
one-way communication pattern. The rough outline of the technique is to inspect the page
for outside links and then attach an event handler to each link that makes a simple one-way
image request to the server. The JavaScript library is shown here:
/* object wrapper */
var AjaxTCRExamples = {};
/* URL of server-side outbound link recording script */
AjaxTCRExamples.linkReportingURL = "http://ajaxref.com/ch2/recordlink.php";
AjaxTCRExamples.encodeValue = function(value)
{
var encodedVal;
if (!encodeURIComponent)
{
encodedVal = escape(val);
FIGURE 2-10 Catching JavaScript errors and viewing error log