javascript - How can I use a cookie? What's wrong? -


i want make code saving cookies.

<script> var user_name; var expires = new date();  if((document.cookie=="")==false){ var lenght = document.cookie.lenght-1; var message=document.cookie.sbstr(5,lenght); document.write(document.cookie); } function check(){ user_name=document.getelementbyid("name").value; expires.setfullyear(expires.getfullyear()+1); document.cookie=escape("name")+"="+escape(user_name) + "; expires = " + expires.togmtstring(); alert(document.cookie); }  </script>   name: <input type="text" id="name" /> <input type="button" value="enter" onclick="check()" /> 

but problem on expires. when execute it, show message on alert:

name=lucas; __utma=1.1375427537.1415045152.1415051179.1415230828.3; __utmz=1.1415045152.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); vtexrcmacidv7=1f3e4180-6545-11e4-92a5-dd43cc28da42; _ga=ga1.1.1375427537.1415045152 

what's wrong? should show correct expiration date?


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -