html [notificaciones jquery con uso de cookies] para mostrar notificaciones x usuario y poder cerrar
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html [notificaciones jquery con uso de cookies] para mostrar notificaciones x usuario y poder cerrar相关的知识,希望对你有一定的参考价值。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
function createNotification(message, type) {
var html = '<div class="alert alert-' + type + ' alert-dismissable page-alert">';
html += '<button type="button" class="close"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>';
html += message;
html += '</div>';
$('body').prepend('<div id="note-holder"></div>');
$(html).hide().prependTo('#note-holder').slideDown();
};
function cookieExist(title){
title = title + "-notify";
if ($.cookie(title) === null ||
$.cookie(title) === "" ||
$.cookie(title) === "null" ||
$.cookie(title) === undefined) {
/* no cookie found */
return false;
} else {
console.log('cookie is set, no ad this time');
return true;
}
}
function setCookie(days, title){
var date = new Date();
var minutes = 60 * 24 * days; //3 days
date.setTime(date.getTime() + (minutes * 60 * 1000));
/* set cookie */
title = title + "-notify";
$.cookie(title, "close", {
expires: date
});
}
// show ad if cookie does not exist
if( !cookieExist("ADG") )
createNotification('Custom Calendars - Coming Soon', 'info');
$('.page-alert .close').click(function(e) {
e.preventDefault();
$(this).closest('.page-alert').slideUp();
setCookie(3,"ADG");
});
</script>
以上是关于html [notificaciones jquery con uso de cookies] para mostrar notificaciones x usuario y poder cerrar的主要内容,如果未能解决你的问题,请参考以下文章