PDA

View Full Version : Display different image depending on domain name...


ric176
05-30-2003, 12:48 PM
Hello!

I'm trying to find a script that will allow me to display a different image depending on the URL in the browser / of the site.... for example:


www.abc.com displays abc.gif
www.xyz.com displays xyz.com


I'm trying to do this as I'm hosting a site that I've registered a few different domain names for.... the content would always be the same except for the company logo (the image) that would change depending on the domain name...

I have the one hosting account and don't want to create new accounts and use frames to display the content...

If it doesn't make sense please let me know, and thanks for your help!!!!

Ric

joh6nn
05-30-2003, 01:22 PM
this is just real quick off the top of my head, but here goes:

switch ( window.location.hostname ) {
case "www.abc.com":
var picUrl = "abc.gif"; break;

case "www.xyz.com":
var picUrl = "xyz.gif"; break;
}

document.images['imageName'].src = picUrl;

if that doesn't help any, let me know, post here again, and i'll see if i can't do a better job.

ric176
05-30-2003, 02:23 PM
Hi

Thanks for your post... I've tried within and without <script> tags and not getting any luck... I'm getting:

Error: 'document.images.imageName' is null or not an object

I'm a complete beginner so need all the help you can spare...

Will the script still work on other pages, eg www.abc.com/123.html and www.abc.com/rjb.html...?

Thank you!!!

Ric

joh6nn
05-30-2003, 05:19 PM
ok, i wasn't sure how much you knew, sorry. this script should work fine, no matter where it's at; it's only examining what domain it's on, not what page it's on.

in order to make it work, though, you need to make the script somehow identify which image you want to be dynamic. the method that i chose to do this ( and if you'd like, i can explain why ) was to use the name attribute, in the image tag. so whatever image you'd like to have change, you need to go in, and add this:

name="something"

where something is anything that you're likely to remember easily.

then, in the script, you need to change this:

document.images['imageName'].src = picUrl;

to look like this:

document.images['something'].src = picUrl;

where something is the same as it was above.

hope that helps.