第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

js,為什么這個postMessage無法向另一個網(wǎng)頁發(fā)送信息

js,為什么這個postMessage無法向另一個網(wǎng)頁發(fā)送信息

newsudhc3634140 2016-11-04 21:12:55
程序目標(biāo):點擊“打開副本網(wǎng)頁”按鈕,然后點擊“發(fā)送信息”向打開的網(wǎng)頁發(fā)送信息,新開的網(wǎng)頁監(jiān)聽并輸出接收的信息。兩個頁面在同個文件夾下網(wǎng)頁1<!DOCTYPE?html> <html> <head> ????<meta?charset="utf-8"> ????<title>主頁</title> </head> <body> ????<button?class="open-copy">打開副本網(wǎng)頁</button> ????<button?class="send-msg">發(fā)送信息</button> ????<script?type="text/javascript"> ????????var?openCopy?=?document.getElementsByClassName("open-copy")[0]; ????????var?sendMsg?=?document.getElementsByClassName("send-msg")[0]; ????????openCopy.onclick?=?function(){ ????????????newPage?=?window.open("practice2.html"); ????????}; ????????sendMsg.onclick?=?function(){ ????????????newPage.postMessage("nihao","practice2.html"); ????????} ????</script> </body> </html>網(wǎng)頁2<!DOCTYPE?html> <html> <head> ????<meta?charset="utf-8"> ????<title>副本</title> </head> <body> ????<button?class="get-msg">接收打印信息</button> ????<script?type="text/javascript"> ????????var?getMsg?=?document.getElementsByClassName("get-msg")[0]; ????????window.addEventListener("message",function(e){ ????????????newMsg?=?document.write(e.data); ????????????getMsg.onclick?=?function(){ ????????????????console.log(e.data); ????????????} ????????},false); ????</script> </body> </html>
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 2744 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號