jaylow Posted May 29, 2011 Share Posted May 29, 2011 i was wondering if you can make a button to switch the background color on a sitejust like you switch on a site the languages from English to chines when you click on a flag of that languagesprobably you can :)so how would i make this?i probably need 2 css style sheets and make a button to switch it from one to the otheri am just wonder how the code would look?and if it is done only in html/css or if you need php or javascript? Link to comment Share on other sites More sharing options...
Ingolme Posted May 29, 2011 Share Posted May 29, 2011 Either Javascript or a server-side language can do it. You can use cookies to remember the selection the user made.With java script: Optional: call an onload handler to load the user's selection from a cookie if there is one. Add an onclick handler to a link. Access the site's <link> element and change its "href" attribute to a certain value based on the link that was clicked Optional: save the new selection in a cookie With PHP: Optional: Load a selection from a cookie if it exists and print out the value in the <link> tag's href attribute. Make a link pointing to the same page and add a query string to the URL with the value of the stylesheet Load the value from $_GET and print it into the <link> element's href attribute. Optional: Save the selection in a cookie. Link to comment Share on other sites More sharing options...
jaylow Posted May 29, 2011 Author Share Posted May 29, 2011 i would like to do it in javascriptis it hard for a beginer to do ? i know nothing about javascript (or php)but got the head first javascript book here and the javascript biblehope that will help do you mabye know any tutorial some where that i could followi tryed to search the web but wel i think i type in the wrong thingsanyway thanks already! Link to comment Share on other sites More sharing options...
thescientist Posted May 30, 2011 Share Posted May 30, 2011 have you read through the javascript tutorials? What part are you stuck on? Link to comment Share on other sites More sharing options...
dsonesuk Posted May 30, 2011 Share Posted May 30, 2011 This is very similar to a previous topic, where a dropdown select was used at http://w3schools.invisionzone.com/index.ph...showtopic=28090you just need to replace changecss(this) with changecss('red'), changecss('green') etc, you could also get away with using just one stylesheet link with id reference, and changing the href link to the style sheet you require. <a href="java script:void(0);" onclick="changecss('blue')">Blue theme</a><br /><a href="java script:void(0);" onclick="changecss('green')">Green theme</a><br /><a href="java script:void(0);" onclick="changecss('red')">Red theme</a><br /> css link create style sheets related to theme 'bluetheme.css', 'greentheme.css' and 'redtheme.css' <link rel="stylesheet" href="bluetheme.css" type="text/css" id="cssstyle" /> js function changecss(styleref){ document.getElementById("cssstyle").href=styleref+"theme.css"; set_cookie("styleref", styleref, 7); //set cookie ref name, value, amount of days to keep cookie} Link to comment Share on other sites More sharing options...
jaylow Posted May 31, 2011 Author Share Posted May 31, 2011 perfect that was what i was looking for thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.