js实现弹窗一个ip在24小时只弹出一次的代码
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等等。
作者:Wicub
免责声明:文章、笔记等仅供分享、探讨、参考等学习之用,因此造成的任何后果概不负责。(如有错误、疏忽等问题,欢迎指正、讨论,谢谢)
本文版权归作者和博客园共有,欢迎转载,但请务必在文章页面明显位置给出原文连接,谢谢配合。