所以我正在加载我的cookie onload,但是当我最初创建一个cookie时,它并没有保存在Chrome中。它在Safari中工作正常,直到我退出并重新启动。这是我的JS与cookies的关系:
console.log("Raw Cookie: "+document.cookie)
var serverIP = document.cookie.replace(/(?:(?:^|.*;\s*)serverIpCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1");
var ipUI = false
console.log("Cookie: "+serverIP)
function checkCookie(){
if (serverIP == ''){
document.getElementById("serverInfoID").style.display='block';
}else if (!(serverIP == '')){
document.getElementById("serverInfoID").style.display='none';
updateDevice(9999);
};
};
function getServerInfo(){
if (!(document.getElementById('usip').value == '')){
var now = new Date();
now.setMonth( now.getMonth() + 1)
if (serverIP == ''){
serverIP = "ws://"+document.getElementById('usip').value+":8000";
document.cookie = "serverIpCookie=" + serverIP + ";";
document.cookie = "expires=" + now.toUTCString() + ";"
}else{
serverIP = "ws://"+document.getElementById('usip').value+":8000";
document.cookie = "serverIpCookie=" + serverIP + ";";
document.cookie = "expires=" + now.toUTCString() + ";"
}
document.getElementById('usipButton').style.background="#f39c12";
updateDevice(9999, true);
};
};