Jump to content

Changing CSS-files


Mark Caryon

Recommended Posts

Greetings all,I have the following problem(s):Assume I have an HTML-page, for example "index.html", and 2 different CSS-files, "fooA.css" and "fooB.css".Is it somehow possible to create a link such thata. you can replace "fooA.css" by "fooB.css" as used stylesheet (of course without creating copies of "index.html"), andb. the selected stylesheet gets carried over to other pages linking from "index.html"?Also, related to this problem, can you pass (in an anchor tag) an argument such that the next page gets loaded with a specific stylesheet?Many thanks in advance.

Link to comment
Share on other sites

It can be done with either JavaScript or PHP. I've done both, and both work nicely.It can't be done without JavaScript or any other language, while this action forces manipulation of the page. (X)html can't do that.The way you can do this, for JavaScript, is (only I guess,) via the URL.Then match the word specific for your next stylesheet from the location, if present, write another <link /> element.The stylesheet links should ALL be written by JavaScript, including the default. So if it finds a variable in the location, it will compare it to all available stylesheets, and their words. eg. if "fooB" is found in the location after "?stylesheet=", it will write the element <link href="fooB.css" ... /> If not present at all or "fooA" is found, it will write <link href="fooA.css" ... />If this is not clear to you, I'll get my ready script for you.For PHP, it can be easilier be done with POST rather than GET (the above way for JavaScript is called via GET). If you want to have a button or anchor to another stylesheet, just let it be the submit action for a certain (hidden) form. Then it can post the stylesheet preference. The next page should search for the post variable to be present, and in PHP, echo the correct stylesheet. So every page that will get the ability to show another stylesheet, gets the script that searches for the post variable, and every page that will get the ability to choose another stylesheet , gets the posting form. Both abilities can be assigned for one page.I can give you my sollution, if you want or are not able to write the scripts by your own. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...