iframe-content.html 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Iframe Content</title>
  5. </head>
  6. <body>
  7. <h2>Iframe Content</h2>
  8. <p>This is the content inside the iframe.</p>
  9. <button onclick="sendMessageToParent()">Send Message to Parent</button>
  10. <script>
  11. function sendMessageToParent() {
  12. // Send a message to the parent window (if same origin)
  13. window.parent.postMessage('Hello from iframe!', '*'); // '*' means any origin (use with caution)
  14. }
  15. // JavaScript within the iframe
  16. console.log("Iframe script running");
  17. // Example: Using debugger statement
  18. // debugger; // Uncomment to pause execution in DevTools
  19. // Example: Accessing elements within the iframe (if same origin)
  20. const iframeContent = document.querySelector('p');
  21. if (iframeContent) {
  22. iframeContent.style.color = "blue";
  23. }
  24. // Example: Receiving a message from the parent (if same origin)
  25. window.addEventListener('message', (event) => {
  26. console.log('Message from parent:', event.data);
  27. });
  28. </script>
  29. </body>
  30. </html>