iframe传值

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('要传的值', '*')

}

*表示无限制,也可以是一个url

子页面:

window.addEventListener('message', function (e) {

    console.log(e.data) // e.data即为父页面中'要传的值'

}, false)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。