zoukankan      html  css  js  c++  java
  • 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等等。

  • 相关阅读:
    Centos8安装MySQL8(社区版)
    DateTime.Now 在.netcore下的格式问题
    HP Socket FAQ
    docker基本操作
    Win10-Docker和VMware运行环境冲突解决办法
    Centos8安装docker-compose
    .net5 RSA
    密码规则之数字、小写、大写、特殊字符,至少满足3个
    .net5 应用程序启动和停止事件
    MySQL中国省市区数据表
  • 原文地址:https://www.cnblogs.com/wicub/p/4380998.html
Copyright © 2011-2022 走看看