如何使弹出窗口每隔一定时间只出现一次

问题描述 投票:2回答:1

我有一个弹出窗口,在我的网站上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">&times;</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);
jquery html bootstrap-modal
1个回答
1
投票

在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.readytimeout函数中设置此代码。

© www.soinside.com 2019 - 2024. All rights reserved.