This is a discussion on "Alternative stylesheets" within the Web Page Design section. This forum, and the thread "Alternative stylesheets are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
Alternative stylesheets
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
||||
|
||||
|
Alternative stylesheets
Can anyone tell me how to switch between alternative stylesheets? I cant work out how. Thanks...
|
|
|
|
#2
|
|||
|
|||
|
The best way I can see is to have a server-side script change the include line...
|
|
#3
|
|||
|
|||
|
or javascript and document.write()
|
|
#4
|
||||
|
||||
|
You would prolly want to make use of a cookie to store the users stylesheet preference. use the server side to check the cookie and serve up the right css file.
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
#5
|
||||
|
||||
|
can't sumbody write me a javascript function for example to help me?
|
|
#6
|
|||
|
|||
|
So basically you want someone to do the work for you? I find it a ton better if people just tell me the logic behind it then I do it myself, or they tell me what I need to use then I try and put them together. You will learn a lot more that way my friend.
|
|
#7
|
||||
|
||||
|
yes im sorry but im not that good really
|
|
#8
|
|||
|
|||
|
A Javascript would be a pretty bad idea for this IMO. If someone has disabled javascript then they won't get a stylesheet at all. You could accomplish this very easily with either ASP of PHP.
If you wish to tackle this in ASP Court Jester, here's the logic. Script checks if cookie exists, if it doesn't, then it serves the default stylesheet. If the cookie exists then it reads the cookie and serves the correct stylesheet. If someone clicks on a link which passes variables to the script, then the script serves that stylesheet (from the variable) and sets a cookie based recording that stylesheet. I could do this in ASP, except I haven't tackled cookies yet. I bet it's simple as pie though, right? |
|
#9
|
||||
|
||||
|
my server wont allow asp....
|
|
#10
|
||||
|
||||
|
what does your server allow?
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
#11
|
|||
|
|||
|
yup Sirkent, cookies + ASP = pie
|
|
#12
|
||||
|
||||
|
my server is just basic free with my web provider... i dont know exactly but ASP pages don't work on it
|
|
#13
|
|||
|
|||
|
Well then to be honest you would be better off sticking to one stylesheet. Like I said, this could be accomplished with Javascript but if someone has disabled it then they won't get a stylesheet at all.
|
|
#14
|
||||
|
||||
|
but if you have a default style sheet then surely that one will be used regardless of the javascript enabled?
|
|
#15
|
|||
|
|||
|
I am not an expert but this is what I used before we switched over to asp.
styleswitcher javascript as follows: function setActiveStyleSheet(title) { var i, a, main; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { a.disabled = true; if(a.getAttribute("title") == title) a.disabled = false; } } } function getActiveStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); } return null; } function getPreferredStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") ) return a.getAttribute("title"); } return null; } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } window.onload = function(e) { var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); } window.onunload = function(e) { var title = getActiveStyleSheet(); createCookie("style", title, 365); } var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); Put something like this in the <HEAD> tag: <style type="text/css" media="all">@import url(/Templates/lightblue_sidebars.css);</style> <link rel="alternate stylesheet" type="text/css" media="screen" title="highcontrast" href="/Templates/accessible_plus.css" /> <link rel="alternate stylesheet" type="text/css" media="screen" title="dyslexia" href="/Templates/dyslexia.css" /> <link rel="alternate stylesheet" type="text/css" media="screen" title="default" href="/Templates/lightblue_sidebars.css" /> <link rel="stylesheet" type="text/css" media="print" href="/Templates/lightblue_sidebars.css" /> <script type="text/javascript" src="/Templates/styleswitcher.js"></script> then add a form with the relevant names of the stylesheets. Such as: <form action="../../test/googoodoll" class="vs0"> <label> <input type="radio" name="radiobutton" value="radiobutton" onClick="setActiveStyleSheet('default'); return false" /> Design View</label> <label> <input type="radio" name="radiobutton" value="radiobutton" onClick="setActiveStyleSheet('highcontrast'); return false" /> High Contrast <input type="radio" name="radiobutton" value="radiobutton" onClick="setActiveStyleSheet('dyslexia'); return false" /> Yellow/Black</label> <label> </label> </form> As I said I am no expert so there is probably a simplier way to do this but this worked for me. |
|
#16
|
||||
|
||||
|
thanks m8
|
|
#17
|
||||
|
||||
|
That works, but really, I would NEVER use javascript unless there is absolutly NO OTHER WAY.
:P
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
#18
|
|||
|
|||
|
is there an asp way to change style sheets depending on browser, basically my css is looking awful in Netscape navigator!
|
|
#19
|
|||
|
|||
![]() |
| Tags |
| alternative, stylesheets |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Alternative to frames | jonnymorris | Web Page Design | 13 | May 10th, 2008 09:23 |
| ppc alternative | timmytots | Webforumz Cafe | 0 | Dec 15th, 2006 17:27 |
| Alternate stylesheets problem | masonbarge | JavaScript Forum | 4 | May 17th, 2006 18:01 |
| Alternative CSS Selection (IE) | Andy K | Web Page Design | 3 | < |