Javascript 如何使弹出窗口在一定时间后出现在网站访问中?
如何在访客停留网站3分钟后弹出一个窗口,它可以是网站的任何页面 我读过一篇使用setTimeout(function(){},time)的文章; 我是JS新手,但每次我添加超时都会破坏我下面的代码 提前谢谢你的帮助 我的代码在下面Javascript 如何使弹出窗口在一定时间后出现在网站访问中?,javascript,cookies,popup,timestamp,Javascript,Cookies,Popup,Timestamp,如何在访客停留网站3分钟后弹出一个窗口,它可以是网站的任何页面 我读过一篇使用setTimeout(function(){},time)的文章; 我是JS新手,但每次我添加超时都会破坏我下面的代码 提前谢谢你的帮助 我的代码在下面 <div id="popup_a" class="popup_ABA"> <table width="100%" border="0" align="center" cellpadding="0" cellspac
<div id="popup_a" class="popup_ABA">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><div>THANK YOU FOR YOUR HELP</div></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="46%" align="right"><a href="#" class="nothanks">No</a></td>
<td width="8%" class="popUpFooter_ABA"> </td>
<td width="46%" align="left"><span class="popUpFooter_ABA"><a href="#" class="dosurvey" onClick="dosurvey('#', 'invitationwindow', 800, 550);">Yes</a></span></td>
</tr>
</table></td>
</tr>
</table>
</div>
<script type="text/javascript">
$(document).ready( function() {
$.cookie('cisit292014', '1', {expires: 15, path: '/'});
setInterval(function() {
if ($.cookie('cisit292014') == 11){
if ($.cookie('01092014') != '1') { // Check for cookie
$.cookie('01092014', '1', { expires: 30, path: '/' });
// TO Unload the Popupbox
function unloadPopupBox(){$('#popup_a').fadeOut("slow");}
// To Load the Popupbox
function loadPopupBox(){$('#popup_a').fadeIn("slow");}
// When site loaded, load the Popupbox First
loadPopupBox();
$('.nothanks').click( function() {unloadPopupBox();});
$('.dosurvey').click( function() {unloadPopupBox();});
}
}
$.cookie('cisit292014', $.cookie('cisit292014') + '1' , {expires: 15, path: '/'});
//alert($.cookie('cisit292014'));
}, 20000);
});
function dosurvey(pageURL, title, w, h) {
var left = (screen.width - w) / 2;
var top = (screen.height - h) / 6;
var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}
</script>
谢谢你的帮助
$(文档).ready(函数(){
$.cookie('CIIT29014','1',{expires:15,path:'/'});
setInterval(函数(){
if($.cookie('CIIT29014')==11){
如果($.cookie('01092014')!='1'){//检查cookie
$.cookie('01092014','1',{expires:30,path:'/'});
//卸载弹出框
函数unloadPopupBox(){$('#popup_a').fadeOut(“slow”)}
//加载弹出框
函数loadPopuBox(){$('#popup_a').fadeIn(“slow”)}
//加载站点时,首先加载popubox
loadPopuBox();
$('.nothanks')。单击(函数(){unloadPopupBox();});
$('.dosurvey')。单击(函数(){unloadPopupBox();});
}
}
$.cookie('CITIT292014',$.cookie('CITIT292014')+'1',{expires:15,path:'/');
//警报($.cookie('CIIT29014'));
}, 20000);
});
功能调查(页面URL、标题、w、h){
var left=(screen.width-w)/2;
var top=(屏幕高度-h)/6;
var targetWin=window.open(页面URL,标题,'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizeable=yes,copyhistory=no,宽度='+w+',高度='+h+',顶部='+top+',左侧='+left);
}
看起来您唯一的问题是需要关闭setInterval块。这就是当前破坏您的代码的原因。上述代码运行良好,我为页面上的任何访问者(非站点)获取弹出窗口,但当我尝试在访问者停留3分钟后加载该弹出窗口时,该弹出窗口会被破坏。您发布的代码无效。因此,要么你没有发布所有内容,要么你搞错了Hi ControlAltDel,我也添加了其余的HTML代码&所有代码都工作正常。有什么建议吗