1、src傳值
父頁面:
<iframe?id="video1"?width="100%"?height="100%" src="/static/jsmpeg-master/view-stream.html?url=live1"?frameborder="0"></iframe>
子頁面:
window.onload?=?function?()?{
? ??let?url?=?'ws://172.18.8.51:8082/'?+?location.href.split('=')[1] //?ws://172.18.8.51:8082/live1
}
2、postMessage
父頁面:
window.onload=function(){
????document.getElementById('iframe').contentWindow.postMessage('要傳的值', '*')
}
*表示無限制,也可以是一個(gè)url
子頁面:
window.addEventListener('message', function (e) {
????console.log(e.data) // e.data即為父頁面中'要傳的值'
}, false)