1. .NET后置代码中获取
Response.Redirect("http://www.baidu.com?id=" +Request.Cookies["size"].Value);
2. js中写入cookie
function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); document.cookie = "size="+escape (self.text() )+";path=/"; }
3. js中获取cookie
function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return (arr[2]); else return null; }
4. js中删除cookies
function delCookie() { //获取当前时间 var date = new Date(); //将date设置为过去的时间 date.setTime(date.getTime() - 10000); //将userId这个cookie删除 document.cookie = "cookieName=0; expires=" + date.toGMTString(); }
时间: 2024-10-13 09:12:50