Javascript Timer / Bootstrap / Wordpress
Javascript Timer / Bootstrap / Wordpress
我在我的Wordpress主题中使用了Twitters Bootstrap的这段代码。有没有办法让用户关闭窗口时,即使在刷新后它也会保持关闭状态?我需要窗口在会话的其余部分或至少一个小时保持关闭状态。
当它站立时,窗户在刷新后重新出现。
<div class="alert alert-note alert-dismissible fade in" role=alert>
<button type=button class=close data-dismiss=alert aria-label=Close>
<span aria-hidden=true>×</span>
</button>
<h2>Upgrade to Pro for £2</h4>
<p>Upgrade to a voclr.it Pro Account for just £2 a month and unlock many great features.</p>
<div class="row">
<div class="col-sm-4">
<h4>Previews</h4>
<img src="<?php bloginfo('template_url') ?>/img/start4.png" alt="start4" width="64" height="64">
</div>
<div class="col-sm-4">
<h4>Premium Sample Packs</h4>
<img src="<?php bloginfo('template_url') ?>/img/pulse2.png" alt="pulse2" width="64" height="64">
</div>
<div class="col-sm-4">
<h4>No More Adverts</h4>
<img src="<?php bloginfo('template_url') ?>/img/forbidden.png" alt="forbidden" width="64" height="64">
</div>
</div>
</div>
下面是一个使用本地存储会话存储的示例,更准确地说。
https://jsfiddle.net/Pigbot/dwbynr6y/
//Check if 'hidden' variable is defined
if (typeof (hidden) !== 'undefined') {
// If the 'hidden' variable is defined don't do anything
} else {
// If the 'hidden' variable is NOT defined
// Check if browser supports Local Storage
if(typeof(Storage) !== "undefined") {
// Set the 'hidden' variable to the value of the local storage item
var hidden = sessionStorage.getItem("theDiv");
// If the 'hidden' variable is set to the string 'hidden' the hide the div
if(hidden === "hidden"){
$('.alert-dismissible').hide();
}
//If the 'hidden' variable is not set to the value of the local
//storage item then the div will be visible and so will the button
//Click function on buttom to set the local storage and fadeout the div
$('button.close').click(function(){
sessionStorage.setItem("theDiv", "hidden");
hidden = sessionStorage.getItem("theDiv");
$('.alert-dismissible').fadeOut();
});
} else {}
}
//This button is an example of removing the item from local storage
$('button.clear').click(function(){
sessionStorage.removeItem("theDiv");
});
window.localStorage - 存储没有到期日期的数据
window.sessionStorage - 存储一个会话的数据(关闭浏览器选项卡时数据会丢失)
相关文章:
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 浮动页脚栏-使用Bootstrap隐藏
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 创建带有和不带有JavaScript的Bootstrap下拉菜单
- 在wordpress一定时间后更改自定义字段
- 如何使MailHandler.php在Wordpress中工作
- WordPress和Bootstrap:下拉菜单不起作用
- Bootstrap Navbar 不会与 Wordpress 切换
- Bootstrap javascript wordpress issue data-toggle="colla
- Javascript Timer / Bootstrap / Wordpress
- Bootstrap 3 Collapse Menu 在 Wordpress 中未展开
- Bootstrap 3 / Wordpress 中的工具提示出现问题
- bootstrap折叠导航在我的wordpress主题手机中不起作用
- Bootstrap carousel开始加载wordpress
- 如何在wordpress上实现bootstrap tour
- 让Bootstrap进入我的WordPress主题—无法获得Javascript文件
- Twitter-Bootstrap-3在Wordpress上无法加载
- 我的Wordpress, Bootstrap主题不与JavaScript一起工作
- register_sidebar() WordPress with bootstrap 3 collapse
- 如何在 Wordpress 中包含 JQuery 和 Bootstrap.min.js