54 Part I: Core Ideas
/* fix the omissions */
encodedVal = encodedVal.replace(/@/g,"%40");
encodedVal = encodedVal.replace(/\//g,"%2F");
encodedVal = encodedVal.replace(/\+/g,"%2B");
}
else
{
encodedVal = encodeURIComponent(val);
/* fix the omissions */
encodedVal = encodedVal.replace(/~/g,"%7E");
encodedVal = encodedVal.replace(/!/g,"%21");
encodedVal = encodedVal.replace(/\(/g,"%28");
encodedVal = encodedVal.replace(/\)/g,"%29");
encodedVal = encodedVal.replace(/'/g,"%27");
}
/* clean up the spaces and return */
return encodedVal.replace(/\%20/g,"+");
}
AjaxTCRExamples.sendRequest = function(url, payload)
{
var img = new Image();
img.src = url+"?"+payload;
}
AjaxTCRExamples.logURL = function(URI)
{
var payload = "site=" + AjaxTCRExamples.encodeValue(URI);
AjaxTCRExamples.sendRequest(AjaxTCRExamples.linkReportingURL, payload);
}
AjaxTCRExamples.regLinks = function()
{
var outLinks;
var curURL = document.domain;
outLinks = document.body.getElementsByTagName("a");
for (var i=0;i<outLinks.length;i++)
{
/* we only want to log the external links, so we check for that first */
var regxp = /^http|https/i;
if (regxp.test(outLinks[i].href) && outLinks[i].href.indexOf(curURL) == -1)
{
if (outLinks[i].addEventListener)
outLinks[i].addEventListener("mousedown", function()
{ AjaxTCRExamples.logURL(this.href); return true; }, false);
else if (outLinks[i].attachEvent)
outLinks[i].attachEvent("onmousedown", function()
{ AjaxTCRExamples.logURL(window.event.srcElement.href); return false; });
}
}
}
if (window.addEventListener)
window.addEventListener("load", AjaxTCRExamples.regLinks, false);