Results 1 to 3 of 3
-
08-11-2004, 10:38 PM #1Junior Guru
- Join Date
- Oct 2001
- Posts
- 193
How to get domain name and assign it to a variable with Javascript?
Can somebody tell me how to go about getting the domain the visitor is accessing my site from (so it will do either domain.com or www.domain.com) and assign it to a variable?
Here's what I need to do:
Code:var HOST = 'NEED DOMAIN HERE'; setCookie('mtcmtauth', f.author.value, now, '/', HOST, ''); setCookie('mtcmtmail', f.email.value, now, '/', HOST, ''); setCookie('mtcmthome', f.url.value, now, '/', HOST, '');
-
08-12-2004, 01:30 AM #2Web Hosting Master
- Join Date
- Jun 2003
- Location
- Janesville, Wi
- Posts
- 1,520
I have contacted one of my Javascript experts to assist.
Code:search_this = ".com"; full_url = document.URL; index = full_url.search(search_this); domain = full_url.substring(index + search_this.length); which can be reduced to: the_url = document.URL.search(".com"); HOST = the_url.substring(the_url + 4);
--Credit to Wray for this response--Jakiao
-
08-12-2004, 03:43 AM #3Junior Guru
- Join Date
- Oct 2001
- Posts
- 193
Thanks for the help Guys!