我正在使用这个 cookie 的 javascript 代码,我想实现这一点:当访问者点击关闭时,div 将隐藏在网站的所有页面上。
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function()
{
if(getCookie('show_cookie_message') != 'no')
{
$j('#cookie_box').show();
}
$j('.cookie_box_close').click(function()
{
$j('#cookie_box').animate({opacity:0 }, "slow");
setCookie('show_cookie_message','no');
return false;
});
});
function setCookie(cookie_name, value)
{
document.cookie = cookie_name+ "=" + escape(value);
}
function getCookie(cookie_name)
{
if (document.cookie.length>0)
{
cookie_start = document.cookie.indexOf(cookie_name + "=");
if (cookie_start != -1)
{
cookie_start = cookie_start + cookie_name.length+1;
cookie_end = document.cookie.indexOf(";",cookie_start);
if (cookie_end == -1)
{
cookie_end = document.cookie.length;
}
return unescape(document.cookie.substring(cookie_start,cookie_end));
}
}
return "";
}
</script>
和
#cookie_box
{
position: fixed;
display: none;
bottom: 0px;
font-size: 0.8em;
z-index: 1000;
background:#393939;
padding:5px;
text-align:center;
width:99%;
color:#ffffff;
}
#cookie_box a:hover
{
color:#ffffff;
text-decoration: underline
}
<div id="cookie_box">Our site requires cookies to function, <a href="/cookies">click here</a> for more information <a href="#" class="cookie_box_close">Close [X]</a></div>
如果我单击“关闭”,它将关闭 cookie_box div,但仅在该页面上。如果我浏览到另一个页面,该 div 将再次可见。任何帮助都会很棒,谢谢!