css - How to store javascript background color change in a session -
i'm creating web based game has 6 different background colours alternate throughout. when button pressed on page sets new colour on next page. if page refreshed reverts original colour. know need store colours in session doesn't happen, unfortunately struggling new javascript , have tried far doesn't work.
this javascript have:
<script> function backgroundyellow() { document.body.style.backgroundcolor = "#f7b538"; } </script> <script> function backgroundblue() { document.body.style.backgroundcolor = "#3cb9c4"; } </script> <script> function backgroundpink() { document.body.style.backgroundcolor = "#c33c55"; } </script> <script> function backgroundgreen() { document.body.style.backgroundcolor = "#8cb369"; } </script> <script> function backgroundorange() { document.body.style.backgroundcolor = "#e57a44"; } </script> <script> function backgroundpurple() { document.body.style.backgroundcolor = "#606ca8"; } </script>
if you're okay @ aiming @ html5 enabled browsers suggest local storage. can store name-value pairs in browser itself. here's pretty way start: http://www.w3schools.com/html/html5_webstorage.asp
example:
// store localstorage.setitem("lastname", "smith"); // retrieve document.getelementbyid("result").innerhtml = localstorage.getitem("lastname");
if want go down route of using sessions should adding server side functionality game - php might best if you're beginner.
Comments
Post a Comment