/    Sign up×
Community /Pin to ProfileBookmark

Display image depending on URL

Bit of a strange request, but hopefully somebody here can help me.

Basically I need a script that will display an image depending on the domain that the page is being viewed from.

For example, if you visit from domain1.com you will see image1.jpg
but if you visit from domain2.net you will see image2.jpg

There are probably easier ways of doing this via php etc. but I need a purely javascript solution, since I’m very limited with what I’m trying to do here.

Thanks an awful lot.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@DeathbyteacupauthorFeb 26.2007 — Okay I've tried this script;

var domain = document.location.split(".");

if(domain[0] == "http://subdomain1")

{

document.write("<img src='image1'>")

}

else

{

document.write("<img src='image2'>")

}

But I get an error and it does not work, I am using subdomains btw.

Please help.
×

Success!

Help @Deathbyteacup spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...