我有一个弹出窗口,在我的网站上10秒内开始,但如果我重新加载页面,它也会重新出现。
我想知道是否有可能只在网页中的用户活动会话中出现一次
HTML:
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body text-center">
<h3 class="text-center" style="color:#434a4d">¡Canjea el <strong>cupón de regalo</strong> del <strong>95%</strong> de descuento<br> para tomar este curso en <strong>$ 9.99 usd!</strong><br><br>
<a href="" target="_blank"><img src="https://ecommerce.tutorialesatualcance.com/vistas/img/plantilla/plantillaCupon.jpg" width="100%"></a>
</h3>
<a href="" target="_blank"><button class="btn btn-success btn-block btn-lg" style="padding:10px">CANJEAR CUPÓN</button></a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
JQUERY:
setTimeout(function(){
$("#myModal").modal();
},10000);
在cookie中设置值如下:
document.cookie = "popupShown=true; max-age=86400"; // 86400: seconds in a day
然后检查你设置的cookie的值,如下所示:
if (document.cookie.indexOf("popupShown=true") == -1) {
document.cookie = "popupShown=true; max-age=86400"; // 86400: seconds in a day
setTimeout(function(){
$("#myModal").modal();
},10000);
}
您可以在document.ready
或timeout
函数中设置此代码。