function
get
(
) {
let
data =
document
.
getElementById
(
'iframe'
).
contentWindow
.
test
()
console
.
log
(
'返回的数据---'
+ data)
</
script
>
window.open打开的页面调用父页面的方法
// 01.html
<button onclick="open1()">打开新页面</button>
<script>
window.addEventListener('message', (event) => {
console.log(event.data)
this.getDetail()
function open1() {
var top = (window.screen.height - 30 - 600) / 2
var left = (window.screen.width - 10 - 1200) / 2
window.open('http://127.0.0.1:5500/02.html', 'newwindow', 'height=600,width=1200,top=' + top + ',left=' + left + ',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
</script>
// 02.html
<button onclick="clickParent()">调用父页面的方法</button>
<script>
function clickParent() {
window.opener.postMessage('调用父页面的方法')
</script>
