1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<form action="2.html">
<input type="password" name="password" id="" />
<input type="text" name="name" id="" />
<input type="submit" value="danji" />
</form>
<script type="text/javascript">
function setCookie(objName, objValue, objHours){
var str = objName + "=" + encodeURI(objValue);
if (objHours > 0) {
var date = new Date();
var ms = objHours * 3600 * 1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
}
var btn = document.getElementsByTagName("input")[2];
btn.onclick=function () {
setCookie("url",window.location.href);
}
</script>
</body>
</html>
2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div>你好</div>
<script type="text/javascript">
function getCookie(objName){
var arrStr = document.cookie.split(";")[0];
var arr = arrStr.split("=");
if(arr[0]==objName){
return decodeURI(arr[1])
}
}
setTimeout(function () {
var urla = getCookie("url");
if(urla){
window.location.href = urla
}
}, 2000)
</script>
</body>
</html>