首页 > 其他 > 详细

14.4 跨域 - hash(比较恶心 不用)

时间:2019-02-02 12:53:58      阅读:179      评论:0      收藏:0      [点我收藏+]

前端

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)

 

14.4 跨域 - hash(比较恶心 不用)

原文:https://www.cnblogs.com/zouxinping/p/10348080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!