You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.4 KiB
HTML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>设置登陆相关的Cookie</title>
</head>
<body>
<div id="ShowBox">
正在设置登陆Cookie信息 ......
</div>
<script>
var cookie = {
set: function (key, val, time) {//设置cookie方法
var date = new Date(); //获取当前时间
var expiresDays = time; //将date设置为n天以后的时间
date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000); //格式化为cookie识别的时间
//设置cookie
document.cookie = key + "=" + val + ";expires=" + date.toGMTString() + ";domain=47.103.96.35;path=/";
// https可以添加 SameSite=None;secure; 以完成iframe跨域cookie(非https单独设置SameSite=None无效) 如下
//document.cookie = key + "=" + val + ";expires=" + date.toGMTString() + ";domain=47.103.96.35;path=/;SameSite=None;secure;";
},
/*获取cookie参数*/
get: function (key) {//获取cookie方法
var getCookie = document.cookie.replace(/[ ]/g, ""); //获取cookie并且将获得的cookie格式化去掉空格字符
var arrCookie = getCookie.split(";") //将获得的cookie以"分号"为标识 将cookie保存到arrCookie的数组中
var tips; //声明变量tips
for (var i = 0; i < arrCookie.length; i++) { //使用for循环查找cookie中的tips变量
var arr = arrCookie[i].split("="); //将单条cookie用"等号"为标识将单条cookie保存为arr数组
if (key == arr[0]) { //匹配变量名称其中arr[0]是指的cookie名称如果该条变量为tips则执行判断语句中的赋值操作
tips = arr[1]; //将cookie的值赋给变量tips
break; //终止for循环遍历
}
};
return tips;
},
delete: function (key) {//删除cookie方法
//获取当前时间
var date = new Date();
//将date设置为过去的时间
date.setTime(date.getTime() - 10000);
//设置cookie
document.cookie = key + "=v; expires =" + date.toGMTString();
}
};
function getUrlParam(name)
{
//构造一个含有目标参数的正则表达式对象
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
//匹配目标参数
var r = window.location.search.substr(1).match(reg);
//返回参数值
if (r!=null) return unescape(r[2]); return null;
};
//Url获取参数
var cookieInfo = { "AIOT_Project": "", "AIOT_Name": "", "AIOT_Token": "" };
cookieInfo.AIOT_Project = getUrlParam("AIOT_Project");
cookieInfo.AIOT_Name = getUrlParam("AIOT_Name");
cookieInfo.AIOT_Token = getUrlParam("AIOT_Token");
//写Cookie
cookie.set("AIOT_Project", cookieInfo.AIOT_Project, 1);
cookie.set("AIOT_Name", cookieInfo.AIOT_Name, 1);
cookie.set("AIOT_Token", cookieInfo.AIOT_Token, 1);
document.getElementById("ShowBox").innerHTML="设置登陆Cookie信息完成";
</script>
</body>
</html>