PDA

View Full Version : Changing CSS through Querystrings.


Mhtml
10-05-2002, 04:57 AM
I have made a little script because I got bored and thought that maybe it might be useful.

So what it does is it writes the <style> properties to the page after requesting cookies. I can make changing the colors work fine but I can't seem to get my fonts to change when I use a similar method as the font color querystrings.


changeprefs.asp:

<%if request.QueryString("r") = 1 then
response.Cookies("contentfont") = "arial"
response.Cookies("preferedstyle") = "true"
end if
if request.QueryString("r") = 2 then
response.Cookies("contentfont") = "times new roman"
response.Cookies("preferedstyle") = "true"
end if
if request.querystring("r") = 3 then
response.cookies("contentfontcolor") = request.QueryString("fontcolor")
response.Cookies("preferedstyle") = "true"
end if
if request.QueryString("r") = 4 then
response.Cookies("afont") = "arial"
response.Cookies("preferedstyle") = "true"
end if
if request.QueryString("r") = 5 then
response.Cookies("afont") = "times"
response.Cookies("preferedstyle") = "true"
end if
if request.QueryString("r") = 6 then
response.Cookies("afontcolor") = request.querystring("linkcolor")
response.Cookies("preferedstyle") = "true"
end if

%>
<%if request.Cookies("preferedstyle") = "true" then%>
<%
afont = request.Cookies("afont")
afontcolor = request.Cookies("afontcolor")
adecoration = request.Cookies("adecoration")
contentfont = request.Cookies("contentfont")
contentfontcolor = request.Cookies("contentfontcolor")
%>



index2.asp :

<%if request.Cookies("preferedstyle") = "true" then%>
<%
afont = request.Cookies("afont")
afontcolor = request.Cookies("afontcolor")
adecoration = request.Cookies("adecoration")
contentfont = request.Cookies("contentfont")
contentfontcolor = request.Cookies("contentfontcolor")
%>
<%styleIT = "<style>"
styleIT = styleIT & "a{font-family:"&afont&";color:"&afontcolor&";text-decoration:"&adecoration&"};"
styleIT = styleIT & "body{font-family:"&contentfont&";color:"&contentfontcolor&"};"
styleIT = styleIT & "</style>"
%>
<%else%>
<%styleIT = "<style>"
styleIT = styleIT & "a{font-family:arial;color:072f95;text-decoration:none};"
styleIT = styleIT & "body{font-family:arial;color:808080};"
styleIT = styleIT & "</style>"
%>

<html>
<head>
<%=styleIT%>
</head...

oracleguy
10-05-2002, 09:37 PM
changeprefs.asp:

<%
Select Case Request.QueryString("r")
Case 1
response.Cookies("contentfont") = "arial"
response.Cookies("preferedstyle") = "true"

Case 2
response.Cookies("contentfont") = "times new roman"
response.Cookies("preferedstyle") = "true"

Case 3
response.cookies("contentfontcolor") = request.QueryString("fontcolor")
response.Cookies("preferedstyle") = "true"

Case 4
response.Cookies("afont") = "arial"
response.Cookies("preferedstyle") = "true"

Case 5
response.Cookies("afont") = "times"
response.Cookies("preferedstyle") = "true"

Case 6
response.Cookies("afontcolor") = request.querystring("linkcolor")
response.Cookies("preferedstyle") = "true"

End Select

%>
<%if request.Cookies("preferedstyle") = "true" then

afont = request.Cookies("afont")
afontcolor = request.Cookies("afontcolor")
adecoration = request.Cookies("adecoration")
contentfont = request.Cookies("contentfont")
contentfontcolor = request.Cookies("contentfontcolor")
%>



index2.asp :




<html>
<head>
<style>
<%if request.Cookies("preferedstyle") = "true" then%>
<%
afont = request.Cookies("afont")
afontcolor = request.Cookies("afontcolor")
adecoration = request.Cookies("adecoration")
contentfont = request.Cookies("contentfont")
contentfontcolor = request.Cookies("contentfontcolor")
%>
a {
font-family: <%= afont %>;
color: <%= afontcolor %>;
text-decoration: <%= adecoration %>;
}

body {
font-family: <%= contentfont %>;
color: <%= contentfontcolor %>;
}

<%else%>
a {
font-family: arial;
color: #072f95;
text-decoration: none;
}

body {
font-family: arial;
color: #808080;
}
<%End If%>
</style>
</head...


Okay I re-wrote most of it :o but it should work now... its much easier to do like what I did on the style part.

I used a select case to improve load time, its a lot faster and more efficent than all those if then statements.