PDA

View Full Version : host name delimiter


cunning-fox
10-03-2002, 11:54 PM
Hi,

I was given this script weeks ago. It checks to make sure that my domain is accessing the site this script is on, and only my site.
It will keep most people off the page that aren't suppose to be there.

The problem is that it doesn't work. Either it doesn't work in "IE" or not at all. Any ideas?

Thanks

<script>
if (location.hostname!="http://www.mysite.com") {
alert("The site that has linked you to this is not authorized.");
location.replace("sorry.html");
}
</script>

adios
10-04-2002, 12:09 AM
The location.hostname property contains the server name, subdomain and domain name/IP address of the current url.

if (location.hostname!="www.mysite.com") {
alert("The site that has linked you to this is not authorized.");
location.replace("sorry.html");
}

Alternately:

if (location.href.indexOf("www.mysite.com") == -1) {

boywonder
10-04-2002, 12:10 AM
try losing the "http://" in your condition

cunning-fox
10-04-2002, 01:44 AM
Hi,

I tried all of the suggestions, same result. Maybe its "IE"? Anyone have any thoughts?

Thanks

adios
10-04-2002, 02:00 AM
Hey, do a little debugging:

alert(location.hostname);

Might as well find out what the script has to work with...

p.s. try location.host

boywonder
10-04-2002, 02:43 AM
or try document.domain

cunning-fox
10-04-2002, 04:17 AM
Hi,

Thanks to the both of you. "document.domain" was the working piece:

<script>
if (document.domain!="my-domain.com") {
alert("Don't have permission");
location.replace("http://www.excite.com");
}
</script>