Bra*_*ter 3 cookies wordpress jquery modal-dialog twitter-bootstrap
我试图让模态每周只弹出一次。
我正在使用 Wordpress 和 Roots 主题,并且正确地将脚本排队和注册。
我的模态代码是
<div class="modal hide fade modalborder" id="myModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<div class="modal-body">
<h2 class="modalheader">Header Here</h2>
<p class="modalcoffee">Text here</p>
<p class="modalcomesin">Text here</p>
</div>
<p class="modallearn">Text Here</p>
<p class="modalready">Are you ready to <span class="modalstart">start</span>?</p>
<a href="#" class="btn btn-info">Click Here</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
使这个节目完美运行的当前javascript:
<script type="text/javascript">
$(window).load(function(){
$('#myModal').modal('show');
});
</script>
Run Code Online (Sandbox Code Playgroud)
我对 jQuery 和 javascript 知之甚少。我需要做什么才能使用 cookie 进行这项工作?
首先,您需要像这样包含JQuery cookie 插件:
<script src="/path/to/jquery.cookie.js"></script>
Run Code Online (Sandbox Code Playgroud)
那么下面的代码应该可以帮助你:
<script type="text/javascript">
$(function(){
// If the cookie does not exist
if ($.cookie('modalshow') === null)
{
// Show the modal
$('#myModal').modal('show');
var expiryDate = new Date();
var hours = 168;
expiryDate.setTime(expiryDate.getTime() + (hours * 3600 * 1000));
// Create cookie to expire in 168 hours (1 week)
$.cookie("modalshow", "false", { path: '/', expires: expiryDate });
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3084 次 |
最近记录: |