views:

1346

answers:

1

I have a page where I grab a value from the query string and add it into a cookie. The value is used for a couple of different items on the page. If the user returns to the page and the value isn't in the query string, the value is pulled back from the cookie.

I have tried doing my own cookie setting and retrieval in JavaScript as well as now using the jQuery Cookie plugin (http://plugins.jquery.com/project/Cookie). Everything works flawlessly...except when I test it in IE6. IE7 and 8 are fine but IE6 always returns a null value for the items when I attempt to retrieve them from the cookie.

I looked at the cookie information in Firefox and I'm not seeing anything beyond the 2 integer values that I set.

Any ideas on what could be causing this in IE6?

UPDATE: I took the test outside of my code into a basic html. Markup below. Same results where it returns null in IE6 (IETester).

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script type="text/javascript" src="Scripts/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="Scripts/jquery.cookie.js"></script>
    <script type="text/javascript">
        $(document).ready(function()
        {
           var testId = GetQueryStringValue("test");

           if (testId == "")
           {
                testId = $.cookie("test");
                alert(testId);
           } 
           else
           {
                $.cookie("test", testId);
                alert("Test set");
           }

            document.write(testId);
        });

        function GetQueryStringValue(name)
        {    
            var regex = new RegExp("[?&]" + name + "(?:=([^&]*))?","i");   
            var tmpURL = window.location.href;    
            var results = regex.exec( tmpURL );    

            if (results == null)
            {
                return ""; 
            }
            else
            {
                return results[1];
            }
        }
    </script>
</head>
<body>

</body>
</html>
+3  A: 

Does the machine running IE 6 have its security settings set to reject cookies? Alternatively, if you are using one of the various techniques that supposedly allow you to run multiple versions of IE on the same machine, be aware that the results are not perfect, and often cause subtle aspects of the browser to break on one or more of the versions: for example, see this comment on Tredosoft's Multiple IE page about cookies failing in IE 6.

NickFitz
The IETest bug with cookies you mentioned above was the cause. Thanks!
JamesEggers