Put something like this in the head of every page: (note: you only really need the bold part in the code of the page with the form/that changes the cookie)
<%
var style = new String(Request.Cookies('style'));
if(style==null || style=='undefined'){
<strong>style = new String(Request.Forms('style'));
if(style==null || </strong><strong>style=='undefined'){</strong>
style="default";
<strong>}else{
Response.Cookies('style') = style;
}</strong>
}
%>
<link rel="stylesheet" type="text/css" href="/styles/style_<%Response.write(style)%>.css"/>
I can't really test that atall; I can't run ASP anywhere.
The principle will work but some of the keywords words might be wrong... (is it Form or Forms?/Cookie or Cookies?) Also; it's not very secure or input-safe. A better way would be to use a keyword/enumeration in the cookie and form, and set the style variable to one of a list of the only allowable values.
For that code to work you'll need to set Javascript as the script language.
(put this line before the code)
<%@ LANGUAGE="JAVASCRIPT" %>
It'd almost be the same with VBScript; although I don't know how you'd test for a null string...
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
Ah; sorry. These two blocks shouldn't be combined:
<%@ LANGUAGE="JAVASCRIPT" %>
<% var style = new String(Request.Cookies('style'));
if(style==null || style=='undefined'){
style = new String(Request.Forms('style'));
if(style==null || style=='undefined'){
style="default";
}else{
Response.Cookies('style') = style;
}
}
%>
You'll probably hit more errors now ^_-
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
The whole problem is that they won't keep things compatible.
We HAD a system where most web code was compatible. But then the elitists pounced, and decided that web code had to be more "elegant." Now we have a bifurcation between the newest browsers and the old ones.
There should be either a criminal penalty for introducing incompatibilities into a system that already works, or the person who introduced the incompatiblity should be forced to pay for the upgrade for everyone in the world.
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
The whole problem is that they won't keep things compatible.
We HAD a system where most web code was compatible. But then the elitists pounced, and decided that web code had to be more "elegant." Now we have a bifurcation between the newest browsers and the old ones.
There should be either a criminal penalty for introducing incompatibilities into a system that already works, or the person who introduced the incompatiblity should be forced to pay for the upgrade for everyone in the world.
Has that got absolutely anything to do with this post, or did you intend it (the reply) to go elsewhere?
But anyway, assuming this is meant here:
ASP code will always be self-compatible because it doesn't matter how old a version of ASP you have on your server. ASP spits out HTML; and it can be as up-to-date or back-in-time as you (as the developer) so choses, If you update your ASP version, you only affect yourself.
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
href="/styles/style_<%Response.write(style)%>.css"
This bit means it will be looking in the /styles/ folder for a file called style_[X].css, where [X] is the value submitted in the field named 'style' from the form/cookie.
I think there's a problem with the null-string checking aswell; in the two places where it says style=='undefined' try: style==''; so:
if(style==null || <strong>style==''</strong>){
style = new String(Request.Forms('style'));
if(style==null || <strong>style==''</strong>){
style="default";
}else{
Response.Cookies('style') = style;
}
}
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
Oops; the problem is that that code is self-restricting.
Any value in the cookie overrides the value from the form; so, once you submit once, you can't submit again.
Corrected part: (ASP only)
<%@ LANGUAGE="JAVASCRIPT" %>
<% var style = new String(Request.<strong>Form</strong>('style'));
if(style==null || style==''){
style = new String(Request.<strong>Cookies</strong>('style'));
if(style==null || style==''){
style="default";
}
}<strong>else{
Response.Cookies('style') = style;
}</strong>
%>
Seems like a minor thing, but it'll make all the difference =P
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
hmmm, i had a quick visit to your page (from that link) with cookies cleared and cookie notifications switched on. The first event is a request to set the style cookie to 'undefined':
This page wishes to set the cookie
style="undefined"
This value will only be sent to documents on the server grafax.co.uk, and paths that are starting in /.
The cookie will be deleted when Opera is closed.
----------------------
Full cookie request:
style=undefined; path=/
So, that means the if(style==null || style='undefined') checks were probably correct... it's a bit weird that O_o. Go with a full test just in case:
<%@ LANGUAGE="JAVASCRIPT" %>
<% var style = new String(Request.Form('style'));
if(style==null || style=='undefined' || style==''){
style = new String(Request.Cookies('style'));
if(style==null || style=='undefined' || style==''){
style="1";
}
}else{
Response.Cookies('style') = style;
}
%>
the line in blue is where you should define the default stylesheet's filename suffix, so a '1' will make the default sheet /styles/style_1.css.
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64