如果body hasClass,只显示一次popup(SweetAlert)

时间:2018-04-04 06:16:48

标签: javascript jquery wordpress sweetalert

目前我的Wordpress主题中有这段代码:

<td width="9%" height="5%">
  <p class="idnumber" title="FTG,EMA,CAS">
    <span title="FTG">FTG<span>,
    <span title="EMA">EMA</span>,
    <span title="CAS">CAS</span>
  </p>
</td>

但是我希望它只运行一次,然后不再在网站上显示它。

怎么做? :)

2 个答案:

答案 0 :(得分:0)

如果一次查看弹出窗口,则将数据保存到浏览器。这是基于您提供的代码的工作示例。在这里,我使用了sessionStorage

&#13;
&#13;
if (!localStorage.getItem("popup")) {
  if ($('body').hasClass('post-template-default')) {
    if(screen.width <= 991) {
        setTimeout(function(){ 
          swal({
          type: 'info',
          title: 'You can swipe!',
          text: 'Swipe to Right or Left to navigate through posts.',
          showConfirmButton: 'false',}) 
          },1000
      ); 
  }
  localStorage.setItem("popup", 'viewed');
}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

代码就像魅力一样,它不起作用,因为它是我在if ( !is_user_logged_in() ){ ?> <script> ... </script> <?php }函数中插入的。谢谢你的回答和时间:)

相关问题