簡體   English   中英

無法設置cookie安全性和HttpOnly屬性

[英]Not able to set cookies secure and HttpOnly properties

無論出於何種原因,當我嘗試通過Javascript設置secure和HttpOnly屬性時,都無法設置它們。 這是正在使用的代碼:

function Selected(StationID,QueryString)
    {
    ClearColours();
    document.getElementById(StationID).className='StationSummary_Container_Selected';
    setCookie('selectedItem',StationID,1);
    setCookie('selectedItemValue',StationID,1);
    setCookie('selectedItemQString',QueryString,1);
    window.location="#" + StationID;
    parent.frames["stationDetail"].location = "StationDetail.aspx?" + QueryString;
    parent.frames["message"].location = "StationMessage.aspx?" + QueryString;
}

function setCookie(NameOfCookie, value, expiredays) {
    var ExpireDate = new Date();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
    var newCookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + "; Secure; HttpOnly";
    document.cookie = newCookie;
}

在此先感謝您提供任何提示。

出於安全原因,瀏覽器不允許您使用JavaScript讀取或寫入HttpOnly屬性。

我想這就是名稱的線索: Http Only

如果需要,可以在服務器上設置這些屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM