469,903 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

CSS-changes depending on document.refferer

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
Jul 20 '05 #1
1 3080
Daniel wrote:
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
}

--
Randy

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

59 posts views Thread by Mason A. Clark | last post: by
1 post views Thread by Jocab | last post: by
145 posts views Thread by Mark Johnson | last post: by
1 post views Thread by Garmt de Vries | last post: by
20 posts views Thread by Tammy | last post: by
3 posts views Thread by nick | last post: by
4 posts views Thread by MikaŽl PLOUHINEC | last post: by
1 post views Thread by shapper | last post: by
11 posts views Thread by New Bee | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.