首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为该弹出javascript添加计时为10秒的rotator函数

为该弹出javascript添加计时为10秒的rotator函数
EN

Stack Overflow用户
提问于 2017-08-09 09:15:02
回答 1查看 120关注 0票数 1

这个脚本旋转5个弹出式标签,为每个网页手动刷新显示一个弹出式标签。我希望脚本自动旋转一个弹出式标签每60秒。

如果一个天才能做到,我将非常感谢他。

问候

代码语言:javascript
复制
<script language="JavaScript">
<!--  
var frequencyCap = 12; 
function setCookie(cookieName,cookieValue, expirehours) {
  if (frequencyCap > 0) {
    var today = new Date();
    var expire = new Date();
    expire.setTime(today.getTime() + 10000 * frequencyCap);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
  } else {
    document.cookie = cookieName+"="+escape(cookieValue);
  }
}
function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
if (ReadCookie('cookie1') != '1') { 
 setCookie('cookie1','1', frequencyCap); 
document.write("TAG POPUP-1");
}else if (ReadCookie('cookie2') != '1') { 
 setCookie('cookie2','1', frequencyCap); 
document.write("TAG POPUP-2");
}else if (ReadCookie('cookie3') != '1') { 
 setCookie('cookie3','1', frequencyCap); 
document.write("TAG POPUP-3");
}else if (ReadCookie('cookie4') != '1') { 
 setCookie('cookie4','1', frequencyCap); 
document.write("TAG POPUP-4");
}else if (ReadCookie('cookie5') != '1') { 
 setCookie('cookie5','1', frequencyCap); 
document.write("TAG POPUP-5");
}
// --> 
</script> 
EN

回答 1

Stack Overflow用户

发布于 2017-08-09 09:36:49

下面是一个简单的计时器函数。您所需要做的就是在代码中切换弹出标记

代码语言:javascript
复制
var timer = setInterval(rotate, 60000);
var idx = 0;

function rotate() {
    if (idx++ < 5) {
    //Insert code to switch popup tags
    document.getElementById("demo").innerHTML = "Index: " + idx;
    //  ^ demo of timer working
    if (idx >= 5)
        idx = 0;
    }
}

https://jsfiddle.net/3t7nqpg7/1/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45580200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档