开发者

Cookie available only in firefox

开发者 https://www.devze.com 2023-04-11 12:35 出处:网络
I set a cookie in a Struts Action using: Cookie c = new Cookie(\"CODE\",\"1\"); c.setPath(\"/\"); c.setMaxAge(120);

I set a cookie in a Struts Action using:

Cookie c = new Cookie("CODE","1");
c.setPath("/");
c.setMaxAge(120);
response.addCookie(c);

And in a asp page, running in the same domain I have the following asp code:

response.write(Request.Cookies("CODE"))

The funny thing is that the cookie is correctly written only when I load the asp using f开发者_C百科irefox. Neither chrome nor ie9 show it properly - cookies are enabled in all three browsers.

What can be happenning ? Thanks in advance


Please try this set and get cookie in Javascript, It will help you.

setCookie("myCookie", "test Data", 3660);

getCookie("myCookie")

// Set Cookie Value    
function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

// Get Cookie Value
function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号