/ Published in: jQuery
This script will automatically route all outbound links through a PHP (or whatever scripting language you prefer) page that can be used for a "You are leaving..." disclaimer and/or click tracking.
Devised for a site that uses a store app, a forum app, and a CMS app that don't talk to each other that well; it would have taken forever to hack all those apps to do the same thing server-side.
DOMAIN-NAME-HERE = YOUR DOMAIN NAME
TLD-HERE = YOUR TLD, IE, "COM" OR "NET"
LINKOUTPAGE.PHP = YOUR TRACKING PAGE (CALLED WITH TARGET URL APPENDED AS "p=[outside url]")
Expand |
Embed | Plain Text
$(document).ready(function() { // BEGIN redirect all outbound links through tracker page $("a").click(function(){ // if it's a full URL... if ($(this).attr("href").indexOf("http")==0) { // if it doesn't go to our site if (!/^http(s){0,1}(.){0,3}(www){0,3}(\.){0,1}DOMAIN-NAME-HERE\.TLD-HERE/.test($(this).attr("href"))){ // send it through the linkout page $(this).attr("href","/LINKOUTPAGE.PHP?p=" + $(this).attr("href")) } } }) // END redirect all outbound links through tracker page };
You need to login to post a comment.
