CSS-changes depending on document.refferer

D

Daniel

Hi, All!

I have a problem - I manage two websites, with two different style sheets
(one for each site), but they both share hte same public message boards and
I want to change the CSS used by the forumn template depending on which site
the user came from - this must be done in JScript, as the boards are hosted
offsite and we cannot edit the serverside language.

Unfortunately, its been over two years since I undertook a serious JScript
project and cannot remember alot of what to do. I was planning on this:
<script language=JavaScript>
if (document.reffer="http://www.website1.com"){
document.write('<link rel="stylesheet"
href="http://www.website1.com/css/css.css" type="text/css">
}
else if (document.reffer="http://www.website2.com"){
document.write('<link rel="stylesheet"
href="http://www.website2.com/css/css.css" type="text/css">
}
else {
document.write('<link rel="stylesheet" href="css/css.css"
type="text/css">
}
</script>

Can anyone help?

Thanks!

Daniel
 
R

Randy Webb

Daniel said:
Hi, All!

I have a problem - I manage two websites, with two different style sheets
(one for each site), but they both share hte same public message boards and
I want to change the CSS used by the forumn template depending on which site
the user came from - this must be done in JScript, as the boards are hosted
offsite and we cannot edit the serverside language.

Unfortunately, its been over two years since I undertook a serious JScript
project and cannot remember alot of what to do. I was planning on this:
<script language=JavaScript>
if (document.reffer="http://www.website1.com"){
document.write('<link rel="stylesheet"
href="http://www.website1.com/css/css.css" type="text/css">
}
else if (document.reffer="http://www.website2.com"){
document.write('<link rel="stylesheet"
href="http://www.website2.com/css/css.css" type="text/css">
}
else {
document.write('<link rel="stylesheet" href="css/css.css"
type="text/css">
}
</script>

Can anyone help?

document.referrer instead of document.reffer is a start :)

The language attribute is deprecated, use the type attribute instead.

= is an assignment, == is a comparison of value.

Might be a better idea to include something in your links though. If a
link is activated via the Favorites/Bookmarks, then document.referrer
will be empty. Same if the URL is typed in.

For testing offline, be advised that document.referrer in IE will be
empty even when a link is clicked. If you open test1.html and link to
test2.html from local files, then test2.html's referrer property will be
empty instead of test1.html

<script type="text/javascript">
if (document.referrer == "Absolute URL to site1") {
//handle site 1 referral
}
if (document.referrer == "Absolute URL to site2") {
//handle site 2 referral
}
if (document.referrer == "") {
//handle no referral
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,131
Latest member
IsiahLiebe
Top