前端
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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。