<script type="text/javascript"> function getCookie(name) { var n = name + "="; var nlen = n.length; var clen = document.cookie.length; var i = 0; while(i < clen) { var j = i + nlen; if(document.cookie.substring(i, j) == n) { var endstr = document.cookie.indexOf(";", j); if(endstr == -1) endstr = clen; return unescape(document.cookie.substring(j, endstr)); } i = document.cookie.indexOf(" ", i) + 1; if(i == 0) break; } return null; } function test(insert) { document.cookie = "nickname=" + escape(insert); //寫入Cookie document.getElementById("codeboxy").innerHTML = getCookie("nickname"); //輸出Cookie } </script> <a href="javascript:test('程式方盒子');">Click me</a> <div id="codeboxy"></div>說明:
自定義getCookie函式,
可掃描cookie內指定之name的中文cookie內容。
沒有留言:
張貼留言