Mark Caryon Posted November 10, 2005 Share Posted November 10, 2005 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 More sharing options...
Champion_Munch Posted November 10, 2005 Share Posted November 10, 2005 I'm not really sure what you're asking...The script you use to link to an external .css file is:<link rel="stylesheet" type="text/css" href="filename.css" />You place this code between the <head> and </head> tags on your html page. :)Sorry if this wasn't what you were asking.with regards Link to comment Share on other sites More sharing options...
Paim Posted November 10, 2005 Share Posted November 10, 2005 A post on switching stylesheets Link to comment Share on other sites More sharing options...
Mark Caryon Posted November 10, 2005 Author Share Posted November 10, 2005 A post on switching stylesheets <{POST_SNAPBACK}> Thanks, Paim, that was exactly what I was referring to... even though I secretly hoped it'd be possible without using JavaScript. Oh well, beggars can't be choosers I suppose. Link to comment Share on other sites More sharing options...
Paim Posted November 10, 2005 Share Posted November 10, 2005 No worries.Im pretty sure that it can be done with PHP as well, but thats getting even more complicated. I've used that script before, and it works a charm. Link to comment Share on other sites More sharing options...
Jack McKalling Posted November 11, 2005 Share Posted November 11, 2005 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 More sharing options...
Mark Caryon Posted November 14, 2005 Author Share Posted November 14, 2005 Thanks for all the help. I think I'll stick with the solution presented by Paim for now, since I don't really know my way around JavaScript and PHP (yet). Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now