利用cookies让sweetalert只出现一次

我一直在使用一个名为SweetAlert的弹出框UI轮子,该系统使用了JS& CSS。它看起来非常好,创建一个一次性的弹出框,一旦关闭,用户将无法再次看到它。

<script>
  swal({
    title: 'Website Maintenance Complete!',
    text: 'For full update log please click <a href="">here</a>',
    type: 'success',
    confirmButtonText: 'Nice!'
  }) 
</script>

我们可以使用Cookie来检测回访者:

if (-1 === document.cookie.indexOf('returning=true')) {

  // run only if cookie not found (-1 means not found)

  swal( ... ); // alert
  document.cookie = 'returning=true'; // set cookie
}

 

posted @ 2022-01-19 16:10  木子欢儿  阅读(42)  评论(0编辑  收藏  举报