December 11, 201312 yr Hi everybody first and foremost i think that this is a fantastic forum and i have learned a lot here thank you everybody. OK i need a little bit of help on a project im working on. It involves cookies so basically i have a website that is nearly done. I want to add a feature where when the user clicks on a button it will change the layout style. I have figured that part out and it works perfectly but i havent figured out how if when the user clicks on it every page should have the new style. I know there are several alternatives like server side but i want to use a cookie for it but i dont know how to do that. Could someone please help me This is the javascript that is being used. function back2(){var elem = document.getElementById("foot");elem.style.backgroundColor = "grey";var elem = document.getElementById("ab");elem.style.backgroundColor = "grey";var elem = document.getElementById("aa");elem.style.backgroundColor = "#E1E1E2";} This is how the HTML looks like <button type="button" onclick="back2()">comfortable </button>
December 11, 201312 yr You could use a cookie or you could possibly use a # from the url? Then once the style has changed when they click a link add the #comfortable to the end of the url and the new page will grab it? Take a look at http://goo.gl/abHhE for using a # as a reference. Hope this helps.
December 11, 201312 yr Author Thats looks nice but i dont want to use JQuery i just want to use a cookie to do that but how to do ?
December 13, 201312 yr There's no inbuilt functions for getting and setting cookies in plain Javascript, so you'll have to create your own ( which is why people use Jquery ).This page has a script you'll find useful - http://www.quirksmode.org/js/cookies.html
Create an account or sign in to comment