cookie_url 使用
:JQUERY :站长发布 :3年前(2022-01-11) :1117次浏览
<html>
<head><title>js_cookie</title></head>
<meta charset = "utf-8" >
<script>
var cookval = window.location.href;
function setCookie(name,value)
{
var exp = new Date();
exp.setTime(exp.getTime() + 1 * 24 * 60 * 60 * 1000); //3天过期
document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exp.toGMTString()+";path=/";
return true;
}
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null)
document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
if(getCookie("first")){
var backurl = document.referrer;
delCookie("back");
setCookie("back",backurl);
delCookie("nows");
setCookie("nows",cookval);
}else{
setCookie("first",cookval);
setCookie("back","null_");
setCookie("nows",cookval);
}
var stricoo = "第一页url="+getCookie("first")+"上页url="+getCookie("back")+"当前url="+getCookie("nows");
alert(stricoo);
</script>
<body>
</body>
</html>
版权声明:本文为云海网站长的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://xn--qiv211ar60a.com/8.html