iframe标签使用传递参数
父级给iframe内部传递参数方法1:很简单,直接在iframe的src数属性中拼接上参数// 发送方:<div><iframe :src="url" id="childFrame" importance="high" name="demo" ></iframe></div>url = `http://localhost:8080/couponMan
·
父级给iframe内部传递参数
方法1:很简单,直接在iframe的src数属性中拼接上参数
// 发送方:
<div>
<iframe :src="url" id="childFrame" importance="high" name="demo" ></iframe>
</div>
url = `http://localhost:8080/couponManager?a={a}` //
接收方:直接使用window.location.search接收,然后对接收到的进行处理
未完待续…
iframe内部给父级传递参数
方法1:使用postMessage方法跨域传递
// 发送方:
top.postMessage("hello", "http://localhost:8081"); // 要写top.postMessage或者是parent.message
// 接收方:
window.addEventListener( "message",
(e)=>{console.log(e.data)}
false);
未完待续…
遇到的问题
1、问题:Failed to execute ‘postMessage’ on ‘DOMWindow’
如果遇到上面的问题可以看下这位大佬的解释:Failed to execute ‘postMessage’ on ‘DOMWindow’
上面的方法都是我自己亲自试过的,完全可用,如果小伙伴还有比较好的方法,可以留言给我,万分感谢~~
更多推荐
已为社区贡献1条内容
所有评论(0)