我正在尝试在我的网站上实施SameSite cookie,但是我不知道我是否正确执行了它,或者即使它正在工作。这是我触摸之前的代码:
/**
* Set cookie
* @param {string} name - cookie name
* @param {string} value - cookie value
* @param {number} expiration - cookie expiration in minutes (-1 = cookies expire when browser is closed)
*/
jQuery.fn.jplist.CookiesService.setCookie = function(name, value, expiration){
var cValue = escape(value)
,exdate = new Date();
expiration = Number(expiration);
if(expiration == -1 || isNaN(expiration)){
document.cookie = name + "=" + cValue + ";path=/;";
}
else{
exdate.setMinutes(exdate.getMinutes() + expiration);
document.cookie = name + "=" + cValue + ";path=/; expires=" + exdate.toUTCString();
}
};
...这是我尝试实现SameSite cookie时所做的事情。我所做的唯一更改是在if / else语句中添加了“ SameSite = None,Secure”:
/**
* Set cookie
* @param {string} name - cookie name
* @param {string} value - cookie value
* @param {number} expiration - cookie expiration in minutes (-1 = cookies expire when browser is closed)
*/
jQuery.fn.jplist.CookiesService.setCookie = function(name, value, expiration){
var cValue = escape(value)
,exdate = new Date();
expiration = Number(expiration);
if(expiration == -1 || isNaN(expiration)){
document.cookie = name + "=" + cValue + ";path=/; SameSite=None,Secure";
}
else{
exdate.setMinutes(exdate.getMinutes() + expiration);
document.cookie = name + "=" + cValue + ";path=/; SameSite=None,Secure; expires=" + exdate.toUTCString();
}
};
有人能告诉我这是否正确还是我错过了什么?我在控制台中测试时不清楚。