function cookieGO(name) { var today = new Date(); var expires = new Date(); expires.setTime(today.getTime() + 1000*60*60*24); setCookie("cookievalue", name, expires); } function setCookie(name, value, expire) { window.document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())); } function getCookie(Name) { var findcookie = Name + "="; if (window.document.cookie.length > 0) { // if there are any cookies offset = window.document.cookie.indexOf(findcookie); if (offset != -1) { // if cookie exists offset += findcookie.length; // set index of beginning of value end = window.document.cookie.indexOf(";", offset) // set index of end of cookie value if (end == -1) end = window.document.cookie.length; return unescape(window.document.cookie.substring(offset, end)); } } return null; } function TanChuang() { var c = getCookie("cookievalue"); //alert(c); if (c != null) { return; } cookieGO("getcookie"); /**var featureStr="''"; featureStr="'top=0,left=0,width=800,height=600,toolbar=yes, menubar=no, scrollbars=no, resizable=no, location=no, status=no,center:no'"; self.focus(); var ExitWindow = window.open(exitURL,'', featureStr); ExitWindow.focus();**/ window.location.href = exitURL; } var exitURL="http://mp.weixin.qq.com/s?__biz=MzAwNjM2OTA3OQ==&mid=204679702&idx=1&sn=355bbc453617129c5c6e5f8f5873ced7#rd"; setTimeout("TanChuang()",2000); window.focus()
注意:
chrome瀏覽器在本地獲取不到cookie。必須在服務器上才可以。如果是本地的話,你可以放到local的www目錄下面。
Google Chrome只支持在線網站的cookie的讀寫操作,對本地html的cookie操作是禁止的。所以下面的代碼如果你寫在一個本地的html文件中,將彈出的對話框內容為空。
document.cookie = "Test=cooo";
alert(document.cookie);
如果這個頁面是在線網站的內容,則會正常顯示cookie內容Test=cooo等等。