PDA

View Full Version : Style Sheet Switcher (v1.1) based on QueryString Parameter



dude9er
11-09-2010, 05:16 PM
I am using the stylesheet switcher on dynamic drive (http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm) . Is there a way to change stylesheets based on a querystring parameter? Basically, if the query string includes "&StyleSheet=BlueStyle" then call and set the BlueStyle.css and cookie on page load.

Any ideas or help would be much appreciated. Thanks!!

ddadmin
11-10-2010, 05:11 PM
Sure, try the below modified .js file, which lets you use the URL parameter to set the stylesheet to use on the page via the syntax:


?StyleSheet=BlueStyle

where "BlueStyle" should be the "title" attribute value of the linked stylesheet in question, for example:


<link rel="alternate stylesheet" type="text/css" media="screen" title="BlueStyle" href="user.css" />


Not thoroughly tested, but should work.

dude9er
11-10-2010, 05:40 PM
Hi ddadmin, thanks, I ran a test and it works well, however I don't see it setting a cookie. Is there a way to do this based on the parameter? Thanks again for your help.

ddadmin
11-10-2010, 06:35 PM
Inside the modified .js file, try finding the below chunk of code, and add to it the line(s) in red:


if (urlselectstyle){
setStylesheet(urlselectstyle)
setCookie("mysheet_r_days", urlselectstyle, 10)
}

The 10 in the above case means 10 days persistence. Again, not fully tested, but should work. :)

dude9er
11-10-2010, 06:45 PM
Hi ddadmin, changed the line to and it worked perfectly. Thanks for your help.

setCookie("mysheet", urlselectstyle, 10)

markf47
03-07-2014, 11:59 AM
Hi, have you still got the modified .js file?

Thanks

zilli
04-03-2014, 07:50 AM
Hi,

I'd like to use the same js query solution. Is the particular file still available?

Thank you!

jscheuer1
04-04-2014, 02:24 AM
This should do it:

5414