[thelist] Getting the base domain in javascript
Samuel Murphy
smurphy at texterity.com
Tue Feb 3 13:50:27 CST 2004
I want to set the base (2nd) level domain when I
set a cookie so that any of the third level
domains can check the cookie. But I didn't want
to hard code a two level domain.
This is the javascript I came up with:
function baseDomainString(){
e = document.domain.split(/\./);
if(e.length > 1) {
return("domain=" + e[e.length-2] + "." + e[e.length-1]) + ";" ;
}else{
return("");
}
}
document.cookie = "GlobalFlag=t;path=/;" + baseDomainString() + "expires=" +
exp.toGMTString();
Is there a more reliable way to get the base domain? Am I
missing the concept totally?
Thanks
Sam
More information about the thelist
mailing list