Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to add event listener to iframe

var iframe = document.getElementById('myIFrame');
iframe.contentWindow.body.addEventListener('mouseup', Handler);

function Handler() {
    alert('works');
}
Comment

how to get event from iframe

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="expires" content="0">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  </head>
  <body>
    <h1>CHILD</h1>
    
    <div>
      <h3>Received data:</h3>
      <div id="placeholder"></div>
    </div>
    
    <script>
    
      /* DEFINITIONS */
      var parentWindow = window.parent;
      
      /*
      * RECEIVE MESSAGE FROM PARENT
      */

      window.addEventListener("message", (e) => {
        var data = e.data;
        console.log("RECEIVED message from PARENT TO CHILD", data);

        document.getElementById("placeholder").innerText = data;

      });
      
      /* SHAKE HAND WITH PARENT */
      window.addEventListener("load", () => {
        parentWindow.postMessage("shakehand", "*");
      });
      
    </script>
  </body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to receive form data in node js 
Javascript :: remove parent element jquery 
Javascript :: how to convert python code to javascript 
Javascript :: set to array js 
Javascript :: types of variables in javascript 
Javascript :: how to scroll element in javascript 
Javascript :: number of factors 
Javascript :: javascript add button 
Javascript :: or js 
Javascript :: ar.js 
Javascript :: what is callback hell in javascript 
Javascript :: fs.writefile promise 
Javascript :: implement the nationalize api using async/await with fetch. 
Javascript :: nextjs link 
Javascript :: react upload image 
Javascript :: how to focus out of an input in testing library 
Javascript :: nlhoman json load from file 
Javascript :: javascript if object element exists 
Javascript :: JavaScript Change the Value of Variables 
Javascript :: javascript Adding Element to the Outer Array 
Javascript :: javascript WeakSets Are Not iterable 
Javascript :: electron InitializeSandbox() called with multiple threads in process gpu-process. 
Javascript :: httpclient post raw json body 
Javascript :: javascript get days difference between two dates 
Javascript :: npm function-memoizer 
Javascript :: phaser place on circles 
Javascript :: phaser reverse animation 
Javascript :: remove text and keep div inside a div jquery 2 
Javascript :: javascript fiori 
Javascript :: Set A Function For An Element 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =