CSS-changes depending on document.refferer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel

    #1

    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=JavaSc ript>
    if (document.reffe r="http://www.website1.co m"){
    document.write( '<link rel="stylesheet "
    href="http://www.website1.co m/css/css.css" type="text/css">
    }
    else if (document.reffe r="http://www.website2.co m"){
    document.write( '<link rel="stylesheet "
    href="http://www.website2.co m/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


  • Randy Webb

    #2
    Re: CSS-changes depending on document.reffer er

    Daniel wrote:
    [color=blue]
    > 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=JavaSc ript>
    > if (document.reffe r="http://www.website1.co m"){
    > document.write( '<link rel="stylesheet "
    > href="http://www.website1.co m/css/css.css" type="text/css">
    > }
    > else if (document.reffe r="http://www.website2.co m"){
    > document.write( '<link rel="stylesheet "
    > href="http://www.website2.co m/css/css.css" type="text/css">
    > }
    > else {
    > document.write( '<link rel="stylesheet " href="css/css.css"
    > type="text/css">
    > }
    > </script>
    >
    > Can anyone help?[/color]

    document.referr er 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.referr er
    will be empty. Same if the URL is typed in.

    For testing offline, be advised that document.referr er 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.refer rer == "Absolute URL to site1") {
    //handle site 1 referral
    }
    if (document.refer rer == "Absolute URL to site2") {
    //handle site 2 referral
    }
    if (document.refer rer == "") {
    //handle no referral
    }



    --
    Randy

    Comment

    Working...