>  기사  >  웹 프론트엔드  >  쿠키를 사용하여 24시간마다 팝업 상자를 설정하는 JS 코드 예제 공유

쿠키를 사용하여 24시간마다 팝업 상자를 설정하는 JS 코드 예제 공유

零下一度
零下一度원래의
2017-04-22 10:05:261513검색

이 글에서는 주로 쿠키를 사용해 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) { // 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; 
 } 
 //提示过期弹框 
 if({$remindflag} == "1"){ 
  setInterval(function TanChuang() { 
  var c = getCookie("cookievalue"); 
  if (c != null) { 
   return; 
  } 
  cookieGO("getcookie"); 
   G.alert({ 
    "title":"过期提示", 
    "pclass":"box", 
    "text":"您的错题本服务将于"+"{$userinfo.member_end}"+"过期<br>为了不影响您的正常使用请续费", 
    "btnText":"购买续费", 
    "alert":function(){ 
     this._remove(); 
     window.location.href = "/manage/pay/readyopenvip.php"; 
    } 
   }); 
  },2000); 
 }

js를 배워야 하는 학생은 PHP 중국어 웹사이트 j의 비디오 튜토리얼에 주목하세요. 많은 js 온라인 비디오 튜토리얼을 무료로 시청할 수 있습니다!

위 내용은 쿠키를 사용하여 24시간마다 팝업 상자를 설정하는 JS 코드 예제 공유의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.