我想在主页上显示弹出窗口,但只显示一次。如果有人去其他页面然后回到主页,我不想再显示它。
以下是代码:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("#displaybox").hide();
message: $('#displaybox'),
css: {
top: ($(window).height() - 391) /2 + 'px',
left: ($(window).width() - 556) /2 + 'px',
width: '556px'
}
});
$('.displayboxclose').attr('title','Click to close').click($.unblockUI);
setTimeout($.unblockUI, 30500);
});
</script>
有人可以帮助您插入Cookie代码吗?
我正在使用jQuery BlockUI插件和jquery-cookie插件
答案 0 :(得分:2)
这样的事可能对你有用;
jQuery(function($) {
if (!$.cookie('blockuicookie')) {
// blockUI scripts goes here.
$.cookie('blockuicookie', true, { "expires": 30, "path": "/" });
setTimeout($.unblockUI, 30500);
}
});
答案 1 :(得分:0)
您不需要使用jquery cookie插件:
function setCookie(name, value, expires, path, domain, secure) {
var caution = false;
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie;
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie;
}
//name - name of the cookie
//* return string containing value
//of specified cookie or null if cookie
//does not exist
function getCookie(name) {
var prefix = name + "=";
var cookieStartIndex = document.cookie.indexOf(prefix);
if (cookieStartIndex == -1)
return null;
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
prefix.length);
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length;
return unescape(document.cookie.substring(cookieStartIndex +
prefix.length,
cookieEndIndex));
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
以这种方式设置cookie调用:
setCookie("dateModified","11/14/2013");
获取cookie:
var lastDate = getCookie("dateModified");