如何设置仅一次显示通知栏的cookie
how to set cookie for display notification bar at only once
我在我的网站上设置了通知,
这是通知栏的 jquery :
function showNotification(params){
// options array
var options = {
'showAfter': 0, // number of sec to wait after page loads
'duration': 0, // display duration
'autoClose' : false, // flag to autoClose notification message
'type' : 'success', // type of info message error/success/info/warning
'message': '', // message to dispaly
'link_notification' : '', // link flag to show extra description
'description' : '' // link to desciption to display on clicking link message
};
// Extending array from params
$.extend(true, options, params);
var msgclass = 'succ_bg'; // default success message will shown
if(options['type'] == 'error'){
msgclass = 'error_bg'; // over write the message to error message
} else if(options['type'] == 'information'){
msgclass = 'info_bg'; // over write the message to information message
} else if(options['type'] == 'warning'){
msgclass = 'warn_bg'; // over write the message to warning message
}
// Parent Div container
var container = '<div id="info_message" class="'+msgclass+'"><div class="center_auto"><div class="info_message_text message_area">';
container += options['message'];
container += '</div><div class="info_close_btn button_area" onclick="return closeNotification()"></div><div class="clearboth"></div>';
container += '</div><div class="info_more_descrption"></div></div>';
$notification = $(container);
// Appeding notification to Body
$('body').append($notification);
var divHeight = $('div#info_message').height();
// see CSS top to minus of div height
$('div#info_message').css({
top : '-'+divHeight+'px'
});
// showing notification message, default it will be hidden
$('div#info_message').show();
// Slide Down notification message after startAfter seconds
slideDownNotification(options['showAfter'], options['autoClose'],options['duration']);
$('.link_notification').live('click', function(){
$('.info_more_descrption').html(options['description']).slideDown('fast');
});
}
// function to close notification message
// slideUp the message
function closeNotification(duration){
var divHeight = $('div#info_message').height();
setTimeout(function(){
$('div#info_message').animate({
top: '-'+divHeight
});
// removing the notification from body
setTimeout(function(){
$('div#info_message').remove();
},200);
}, parseInt(duration * 3000));
}
// sliding down the notification
function slideDownNotification(startAfter, autoClose, duration){
setTimeout(function(){
$('div#info_message').animate({
top: 0
});
if(autoClose){
setTimeout(function(){
closeNotification(duration);
}, duration);
}
}, parseInt(startAfter * 5000));
}
这是我在索引页中添加的代码:
<script >
function showAutoCloseMessage(){
showNotification({
message: "You cart total must be at least $200 for free shipping",
autoClose: true,
duration: 2
});
}
$(document).ready(function() {
showAutoCloseMessage();
});
</script>
现在我需要为此设置 cookie。我需要,当用户进入网站时,那个时候只显示通知栏,之后不显示。我的意思是,当用户重新加载网站时,不显示通知栏。
有人可以帮助我吗?提前谢谢。
你可以使用cookie插件并提出条件,
if ($.cookie('setCookie') == null) {
...
}
相关文章:
- notify.js没有'如果另一个窗口被聚焦,则不显示通知
- 在ajax调用后在rails中显示通知
- Cordova:如何显示系统通知
- Toast通知未显示在右下角
- 通知权限被拒绝(桌面推送通知).通知弹出窗口不会't以镀铬显示
- Chrome扩展通知未显示contextMessage
- 重定向后在页面上显示通知
- Chrome扩展-在全屏视频顶部显示自定义通知/弹出窗口(HTML元素)
- 我们如何在jQuery/php/mySQL中显示最近的通知
- 按钮未显示在 Firefox WebExtension 通知中
- 显示当前的脸书通知
- 仅当标签页处于非活动状态时,才会显示 Chrome 桌面通知
- 是否可以在桌面通知正文JavaScript中显示图标
- 如何不显示重复的谷歌浏览器通知
- 无法发送应用请求,显然已发送,但未显示通知用户
- 使用AngularFire创建用户并调用工厂以显示通知
- 如何在显示 jquery 通知时检测 esc 按键
- Android上Chrome的通知显示在哪里?
- Mozilla通知显示浏览器点击
- 通过jQuery通知显示变量