要点:
A页面通过window.open(“indexB.html”)打开B页面
B页面通过window.opener.A页面中的内容
indexA.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>页面A</title>
</head>
<body>
<form>
<input type="text" id="send">
<input type="button" value="登录" onclick="change()">
</form>
<script>
function change(){
window.open("indexB.html");
}
</script>
</body>
</html>
indexB.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>页面B</title>
</head>
<body>
<h3 id="h3"></h3>
<script>
let h3 = document.getElementById("h3");
h3.innerHTML='从indexA页面中接收到的内容为:'+window.opener.document.getElementById("send").value;
</script>
</body>
</html>
运行indexA.html,在文本框中输入“咖啡泡泡”,运行结果如下:
点击登录,切换到indexB.html页面,将h3的innerHTML值设置为从页面A中获取的文本框值,结果如下: