14.4 window.name
阿新 • • 發佈:2019-02-01
rip nbsp ons cti load true log span .html
a.html
<!-- a和b是同域的:http://localhost:3000 c是獨立的:http://localhost:4000 a獲取c的數據 a先引用c c把值放到window.name上,把a引用的地址改到b --> <iframe src="http://localhost:4000/c.html" frameborder="0" onload="load()" id="iframe"></iframe> <script> let first = true function load() { if (first) { let iframe= document.getElementById(‘iframe‘) iframe.src = ‘http://localhost:3000/b.html‘ first = false } else { console.log(iframe.contentWindow.name) } } </script>
b.html 空頁面
c.html
<script> window.name = ‘我不愛你‘ </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 window.name