![](/img/trans.png)
[英]Trying the SameSite attribute fix for the google recaptcha v2 warning on Chrome 77 doesn't seem to be working for me?
[英]Chrome and IE doesn't work with SameSite attribute?
我嘗試學習如何設置 cookie,但是當我嘗試使用 chrome/IE 打開我的頁面時,就像沒有 cookie 一樣......但在 Firefox 中一切正常! 我已經嘗試刪除“sameSite 屬性和安全”,這適用於所有導航器,但我在 Firefox 中有一條錯誤消息,例如:“您需要提供 sameSite 屬性等。” 有人可以幫助我嗎? 這是我的代碼
function creerCookie(result){
document.cookie = 'Cookie='+result+ '; SameSite:"Lax";secure '
console.log(document.cookie)
}
function getCookie (name){
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
let body = document.body
let kiki = getCookie('Cookie')
console.log("voila :"+kiki)
if (kiki==="test1"){
body.style.background = "red"
}else if (kiki === "test2"){
body.style.background = "green"
}
問題在於Secure
屬性。 從這個文檔中,我們可以知道
具有
Secure
屬性的 cookie 僅與通過 HTTPS 協議的加密請求一起發送到服務器,從不使用不安全的 HTTP。不安全的站點(在 URL 中帶有
http:
:)不能使用Secure
屬性設置 cookie。
您可以通過https
托管您的測試頁面,然后代碼將在 IE 和 Chrome 中運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.