<p>setCookie</p> <script> function setCookie(c_name,value,expiredays){ var path = location.pathname; var paths = new Array(); paths = path.split("/"); if(paths[paths.length-1] != ""){ paths[paths.length-1] = ""; path = paths.join("/"); } var extime = new Date().getTime(); var cltime = new Date(extime + (60*60*24*1000*expiredays)); var exdate = cltime.toUTCString(); var s = ""; s += c_name +"="+ escape(value); s += "; path="+path; if(expiredays){ s += "; expires=" +exdate+"; "; } else { s += "; "; } document.cookie = s; } window.onload = setCookie('test', 'sample', 7); </script>