1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="div" style="height: 200px;width: 200px" >
<button id="button">点击</button>
<button id="button2">点击</button>
</div>
<script>
var div= document.getElementById("div");
var button= document.getElementById("button");
var button2= document.getElementById("button2");
var bgcolor = window.localStorage.getItem('bgcolor');
console.log(bgcolor)
button.onclick=function () {
bgcolor =prompt("请输入颜色");
window.localStorage.setItem('bgcolor',bgcolor);
div.style.background = bgcolor;
}
button2.onclick=function () {
parent.location="2.html"
}
</script>
</body>
</html>
2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2</title>
</head>
<body id="body">
<script>
onload=function () {
bgcolor = window.localStorage.getItem('bgcolor');
document.getElementById("body").style.background=bgcolor;
}
</script>
</body>
</html>