14.4 跨域 - hash比较恶心 不用

前端

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)

 

相关文章

根据官网 入门 express
java叫接口control什么的app.get.post等等都是请求方式我们可...
为了前端丢进去的时候可以直接判断中间件就是经过了这个就会...
Express 文件的上传和下载
运行命令下载app.js 增加中间件。
基本模板来的 后面用后就有什么加什么都行。