1 window.onbeforeunload = function () { 2 delCookie("CookieName"); 3 } 4 //删除cookies 5 function delCookie(name) { 6 var exp = new Date(); 7 exp.setTime(exp.getTime() - 1); 8 var cval = getCookie(name); 9 if (cval != null) 10 document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); 11 } 12 13 function getCookie(name) { 14 var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); 15 if (arr = document.cookie.match(reg)) 16 return (arr[2]); 17 else 18 return null; 19 }