Javascript cookies duration -


i using function read , write cookie little php in , working fine. need add duration of 7 days in it. can plz let me know , how can add beginner in javascript , dont have clue update code.

        <script language="javascript">         writecookie();         function writecookie()         {             the_cookie = document.cookie;             if(the_cookie)             {                 the_cookie = "pixelratio="+window.devicepixelratio+";"+the_cookie;                 document.cookie = the_cookie;                  if(window.devicepixelratio > 1)                 {                     location = '<?php echo $_server['php_self']?>';                 }             }         }     </script> 

you can use 1 of following attribute set duration cookie.

expires - date when cookie expire , thrown away. example, today 26th march 2013, if want set duaration 7 days, code below
document.cookie="acookie=avalue; expires=tue, 02 apr 2013 23:59:59 gmc";

max-age - number representing seconds until expiration. have calculate seconds days. example 7 days duration (60*60*24*7), code follows

document.cookie="acookie=avalue; max-age=604800 "; 

note : browsers not support max-age attribute. on browsers support it, if max-age , expires attribute both set, max-age has precedence on expires.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -