User controlled style sheets

Soldato
Joined
25 Jan 2003
Posts
11,550
Location
Newark, Notts
I have a script (JavaScript) which enables a user to switch between two style sheets on a website. Only problem is, when they visit a different page in the site, the style sheet goes back to the default.

I'm doing the site in ASP.NET and it doesn't have a user logins or anything. I just want the style sheet to at least stay as the user has selected until the browser is closed, is this possible?

The script is below, it was taken from a tutorial on the web (i'm a beginner to this):

Code:
<script language="JavaScript">
<!--
var doAlerts=true;
function changeSheets(whichSheet){
  whichSheet=whichSheet-1;
  if(document.styleSheets){
    var c = document.styleSheets.length;
    if (doAlerts) alert('Change to Style '+(whichSheet+1));
    for(var i=0;i<c;i++){
      if(i!=whichSheet){
        document.styleSheets[i].disabled=true;
      }else{
        document.styleSheets[i].disabled=false;
      }
    }
  }
}
//-->
</script>

And then two links at the bottom for each style sheet:

Code:
<a href="JavaScript:changeSheets(1)"><img src="images/stylesheetcolour2.gif" alt="Blue" border="0"></a>
<a href="JavaScript:changeSheets(2)"><img src="images/stylesheetcolour1.gif" alt="Red" border="0"></a>

And obviously the two style sheet bits in the head tags:

Code:
 <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <link href="StyleSheet2.css" rel="stylesheet" type="text/css" />
 
Last edited:
never thought about sessions, only ever done them in php, i'll look into it ta!

Edit: just having a quick think before i head out... could I change the href part of the link tag below to a variable? And then let the user select the stylesheet from a drop down menu? Each of which have the value of the filename.

<link href="StyleSheet.css" rel="stylesheet" type="text/css" />

Shouldn't be too hard should it? And then add their choice to the session variable.

Sorry if this sounds a bit messed up, I get what I mean in my head though.
 
Last edited:
Ok i've been looking for hours now trying to figure this out and I can't :(

Can anyone help? I just can't get my head round VB or ASP.NET, php is so much easier :(
 
mixture of cookies for storing previous / last visit settings and sessions for continuation. theres other ways also but those seem the easiet depending on your web setup.
 
Sorted it using javascript and cookies!

I had a look at a couple of those videos last night and they were quite helpful but they didn't help me to understand this particular problem. I think I just suck at programming :(
 
just if you can try and cover it so that those that dont user javascript / cookies get default stylesheet rather then the whole thing going wierd
 
Back
Top Bottom