Created
December 16, 2010 11:33
-
-
Save struberg/743303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
function getFullUrl(url) { | |
var urlparts = url.split(/&|\?/g); | |
var urlpath = urlparts[0]; | |
if (urlpath.indexOf('://') < 0) { | |
if (urlpath[0]== '/') { | |
return urlpath; | |
} | |
else { | |
var startpathloc = window.location.pathname.lastIndexOf('/'); | |
return window.location.pathname.substring(0, startpathloc+1) + urlpath; | |
} | |
} | |
return url; | |
} | |
function addWindowCookie(url) { | |
var windowId = window.name; | |
if (windowId == undefined) { | |
return; | |
} | |
// 2 seconds expiry time | |
var expdt = new Date(); | |
expdt.setTime(expdt.getTime()+(1*1000)); | |
var expires = "; expires="+expdt.toGMTString(); | |
var fullurl = getFullUrl(url); | |
var pathName = encodeURIComponent(fullurl.replace(/\//g, "")); | |
document.cookie = pathName + '-codiWindowId=' + windowId + expires; | |
} | |
window.onload = function() { | |
var anchors = document.getElementsByTagName("a"); | |
var i=0; | |
for (i=0;i<anchors.length;i++) { | |
var a = anchors[i]; | |
if (a.getAttribute('onclick') == undefined) { | |
var url = a.getAttribute('href'); | |
a.setAttribute('onclick', "addWindowCookie('" + url + "'); return true;") | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment