123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>Iframe Example</title>
- <style>
- #myIframe {
- width: 600px;
- height: 400px;
- border: 1px solid black;
- }
- </style>
- </head>
- <body>
- <h1>Parent Page</h1>
- <iframe id="myIframe" src="iframe-content.html"></iframe>
- <script>
- let _log = console.log;
- // console.error = () => {}
- console.log = (...args) => {
- _log.apply(this, args)
- }
- // JavaScript in the parent page (can interact with the iframe if same origin)
- const iframe = document.getElementById('myIframe');
- // Example: Sending a message to the iframe (if same origin)
- // iframe.contentWindow.postMessage('Hello from parent!', '*'); // '*' means any origin (use with caution)
- // Example: Receiving a message from the iframe (if same origin)
- window.addEventListener('message', (event) => {
- // if (event.origin === 'http://your-iframe-domain.com') { // Check origin for security
- console.log('Message from iframe:', event.data);
- // }
- });
- </script>
- </body>
- </html>
|