如何在客户端检测用户是否刚刚在启用“从我离开的地方继续”的情况下重新打开 chrome?
我想根据用户是否刚来自相关页面来修改客户端行为。重新打开浏览器不应激活此行为,但会保留 document.referrer
。
最佳答案
您可以使用 Cookie。 cookie 存储在客户端,可以通过 javascript 设置和检索它们(如果浏览器配置允许的话)。 Here you have examples for setting ang getting cookies with javascript.
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value; /* In this line you set the value */
}
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "="); /* In this line you get the key */
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end)); /* In this line you get the value */
}
return c_value;
}
您可以在这里获得更多信息:http://www.w3schools.com/js/js_cookies.asp
关于javascript - 从客户端 javascript 检测 Chrome 重启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17028475/