如何杀死僵尸饼干

pse*_*ma4 6 html javascript cookies

我不确定我的问题是否与问题有关.

关闭浏览器后,IE9会删除此cookie(预期),但Chrome 12,Firefox 5和Opera 11不会.(在测试下面的示例时,单击"删除帐户"后,每个浏览器都被关闭.然后在短时间内重新打开它们,除了IE9之外,所有浏览器仍然存在.)

使用案例: Cookie在用户上次访问后1年到期.帐户删除应删除cookie.

问题:
(1/2)为什么IE9做正确(预期)的事情而其他人不做?
(2/2)如何确保所有浏览器都销毁此cookie?

例:

的login.html

<!doctype html>
<html>
    <head>
        <title>Create Cookie Example</title>

        <script>
            function setCookie() {
                var expDate = new Date();
                expDate.setDate(expDate.getDate() + 365);
                document.cookie = "fakeCookie=" + escape("fake value")
                    + "; expires=" + expDate.toGMTString();
            }
        </script>
    </head>

    <body onload="setCookie()">
        <h1>Welcome</h1>
        <p>Lorem ipsum...</p>
        <hr size="1" />
        <p><a href="profile.html">User Profile</a></p>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

profile.html

<!doctype html>
<html>
    <head>
        <title>Delete Cookie Example</title>

        <script>
            function deleteConfirm() {
                if ( confirm("Are you sure you want to delete your account? "
                           + "All data will be lost; this action cannot be undone!")
                   ) deleteConfirmed()
                else return false

                return true;
            }

            function deleteConfirmed() {
                document.cookie = "fakeCookie=; expires=Thu, 01-Jan-70 00:00:01 GMT";
            }
        </script>
    </head>

    <body>
        <h1>User Profile</h1>
        <p>Lorem ipsum...</p>
        <hr size="1" />
        <p><a href="index.html" onclick="return deleteConfirm()">Delete Account</a></p>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:原始帖子错误地将login.html识别为index.html(形成循环引用,以便在删除"帐户"时重新创建cookie.)

Pop*_*ops 5

OP提出了这个答案,最初将其编辑成问题.对于语义而言,这只是将解决方案保留在答案帖子中的转贴.

        <script>
            function deleteConfirm() {
                if ( confirm("Are you sure you want to delete your account? "
                           + "All data will be lost; this action cannot be undone!")
                   ) deleteConfirmed(); // <-- ** MISSED SEMICOLON HERE **
                else return false;      // <-- ** AND HERE **

                return true;
            }

            function deleteConfirmed() {
                document.cookie = "fakeCookie=; expires=Thu, 01-Jan-70 00:00:01 GMT";
            }
        </script>
Run Code Online (Sandbox Code Playgroud)