Using javascript to set cookie in IE

前端 未结 2 1760
忘了有多久
忘了有多久 2021-02-15 15:48

document.cookie= \"cookiename=cookievalue; expires=Mon,12Jun2015:00:00:00; path=/;\"

I run this script on my Internet Explorer 10 but it d

2条回答
  •  心在旅途
    2021-02-15 16:19

    The following sample code will demonstrate setting a cookie of your choosing directly, without requiring input from the user. To store a cookie from your site, simply put a call to the javascript function in your HTML page, like this:

    
    

    The real work is done by the cookieSet() javascript function, which can be either in the area of your HTML page, or in a separate javascript file:

    var cookieText = "Put your desired cookie value here";
    var cookiePrefix = "";
    var myPage = location.href;
    var wwwFlag = myPage.indexOf('www');
    if (wwwFlag > 0) {
    cookiePrefix = "www";
    }
    var cookieName = cookiePrefix + "cbCookie";
    function cookieSet() {
    if (document.cookie != document.cookie) {
    index = document.cookie.indexOf(cookieName);
    } else {
    index = -1;
    }
    if (index == -1) {
    document.cookie=cookieName+"="+cookieText+"cbEndCookie; expires=Monday, 04-Apr-2020 05:00:00 GMT";
    }
    }
    

提交回复
热议问题