前端
a.html
<!-- a和b同域,和c跨域 路径后面的hash值可以用来通信 目的:a想访问c a给c传一个hash值 c收到hash值后 c把hash值传递给b b将结果放到a的hash值中 --> <iframe src="http://localhost:4000/c.html#iloveyou"></iframe> <script> window.onhashchange = () => { console.log(location.hash) } </script>
b.html
<script> // window.parent是c window.parent.parent是a window.parent.parent.location.hash = location.hash </script>
c.html
<script> console.log(location.hash) const iframe = document.createElement(‘iframe‘) iframe.src = ‘http://localhost:3000/b.html#idontloveyou‘ document.body.appendChild(iframe) </script>
后端
a.js
let express = require(‘express‘) let app = express() app.use(express.static(__dirname)) app.listen(3000)
b.js
let express = require(‘express‘) let app = express() app.use(express.static(__dirname)) app.listen(4000)
原文地址:https://www.cnblogs.com/zouxinping/p/10348080.html
时间: 2024-10-18 10:28:19