Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
hey all im trying to get this cookie remember when the browser is closed, it currently works if u reload the page.

any help with be greatly appreciated

HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Five</title>
<link rel="icon" 

      type="image/x-icon" 

      href="icon.ico">
<script type="text/javascript">

JavaScript
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=Jrop/five/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"Jrop/five/",-1);
}
var backColor = new Array();

backColor[0] = '#333333';//grey
backColor[1] = '#0066CC';//blue
backColor[2] = '#00CC66';//green
backColor[3] = '#F5C605';//yellow
backColor[4] = '#663399';//purple
backColor[5] = '#F00';//red
backColor[6] = '#FF3366';//pink
backColor[7] = '#00CC99';//turquose
backColor[8] = '#FF6633';//orange 

function changeBG(whichColor){
document.body.style.backgroundColor = backColor[whichColor];
createCookie('backColor', whichColor);
}

if(readCookie('backColor'))
document.write('<style type="text/css">body {background-color: ' + backColor[readCookie("backColor")] + ';}<\/style>');
HTML
</script>
</head>


  </ul>

  <!-- tab containers -->
  <div id="Background">
  <h4>Color</h4>
  <div class="split"></div>
    <div id="colorbox">
   <a href="java<!-- no -->script:changeBG(0)"> <div id="pickbox" class="grey"></div></a>
    <a href="java<!-- no -->script:changeBG(1)"><div id="pickbox" class="blue"></div></a>
    <a href="java<!-- no -->script:changeBG(2)"><div id="pickbox" class="green"></div></a>
    <a href="java<!-- no -->script:changeBG(3)"><div id="pickbox" class="yellow"></div></a>
    <a href="java<!-- no -->script:changeBG(4)"><div id="pickbox" class="purple"></div></a>
    <a href="java<!-- no -->script:changeBG(5)"><div id="pickbox" class="red"></div></a>
    <a href="java<!-- no -->script:changeBG(6)"><div id="pickbox" class="pink"></div></a>
    <a href="java<!-- no -->script:changeBG(7)"><div id="pickbox" class="turquose"></div></a>
    <a href="java<!-- no -->script:changeBG(8)"><div id="pickbox" class="orange"></div></a>
    
    </div>


thanks
Posted
Comments
Ed Nutting 3-Mar-12 5:03am    
This may not be a code issue. Have you got your browser set to delete cookies on browser close?
Jrop_ 4-Mar-12 4:21am    
no, i have done it on all my devices and still doesn't save

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900