在页面加载时立即停止cookie设置

Stop cookie setting immediately on page load

本文关键字:cookie 设置 加载      更新时间:2023-09-26

有一个问题,在一些JS中,cookie在页面加载时设置,当它应该只在我点击关闭框时设置。

任何帮助都会很感激。下列代码:

<!doctype html>
<html lang="en">
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://resources.site.co.nz/scripts/jquerycookie.js"></script>
    <script type="text/javascript">
    $(function() {
        $('a.close').click(function() {
            $(this).parent().fadeOut(1500);
            $.cookie('hidden', 'true', { expires: null});
            alert($.cookie('hidden'));
            return false;
        });
        if($.cookie('hidden','true')){
            $('#errororganinfoinchide-this').hide();
        }
    });
    </script>
</head>
<body>
    <div id='boxes'>
        <aside class='warning' id='errororganinfoinchide-this'>
            <a href='#errororganinfoinchide-this' class='close'><img src='http://resources.site.co.nz/backgrounds/close.png' /></a>
            <img src='http://resources.site.co.nz/backgrounds/icon_warning.png' class='messageimg' />
            <h4>Warning - Organisation Info</h4>
            <p>Sorry, there was an error opening the "Organisation Info" Box. Please try again later.</p>
        </aside>
    </div>
</body>

行" if($.cookie('hidden','true')){ "不设置cookie而不是读取它吗?

应该是这样的…

if($.cookie('hidden') == 'true'){