window.postmessage
<html> <head> <title>test</title> <style> iframe{ border: 1px solid red; } </style> </head> <body> <iframe src="./content.html" frameborder="0" id='receiver'></iframe> <script> window.onload = () => { var receiverWindow = document.getElementById('receiver').contentWindow; receiverWindow.postMessage('hello','*') } </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <p>postmessage</p> <script> window.addEventListener('message',function(e){ console.log('message is ok',e.data); },false) </script> </body> </html>