jqueryjquery-pluginscookies

JQuery Cookie not working on chrome


I'm running this code,

<html>
    <head>
        <title>D</title>
        <script type="text/javascript" src="jQuery.js"></script>
        <script type="text/javascript" src="Cookie.js"></script>
        <script type="text/javascript">
            $(document).ready( function() {
                $.cookie("d", "1") ;
            }) ;
        </script>
    </head>

    <body>
            <script type="text/javascript">
                alert( $.cookie("d") ) ;
            </script>
    </body>
</html>

It's showing '1' on Firefox, IE, but 'null' in chrome. Any idea why? I'm using latest jQuery and cookie plugin from http://plugins.jquery.com/files/jquery.cookie.js.txt


Solution

  • Chrome doesn't support cookies for locals unless you start it with the --enable-file-cookies flag. You can read a discussion about it at here

    *Chrome does support cookies if you use the local IP address (127.0.0.1) directly. so in the localhost case, that could be an easier workaround.