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

apply eventlistener to iframe

var iframe = document.getElementsByTagName('iframe')[0],
    iDoc = iframe.contentWindow     // sometimes glamorous naming of variable
        || iframe.contentDocument;  // makes your code working :)
if (iDoc.document) {
    iDoc = iDoc.document;
    iDoc.body.addEventListener('afterLayout', function(){
                        console.log('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 :: eslint no-param-reassign 
Javascript :: Delete spaces in text in javascript 
Javascript :: download image from url javascript 
Javascript :: create hash in node js 
Javascript :: Error: Expected "payload" to be a plain object. at validate 
Javascript :: js greater than or equal to 
Javascript :: how to get session javascript ws3schools 
Javascript :: style display block js 
Javascript :: first non repeating character javascript 
Javascript :: javascript check if object is object 
Javascript :: common character count javascript 
Javascript :: refresh page js 
Javascript :: convert seconds to hours minutes seconds javascript 
Javascript :: javascript lerp 
Javascript :: how to filter an array of objects in javascript 
Javascript :: javascript date to utc format 
Javascript :: generate random otp in node js 
Javascript :: ajaxcall 
Javascript :: javascript ascii to hex 
Javascript :: remove item from localstorage 
Javascript :: react js input autocomplete off 
Javascript :: js do after delay 
Javascript :: nodejs chaning env variable at runtime 
Javascript :: @jsonignore unrecognized field 
Javascript :: Sort numbers from an array in javascript 
Javascript :: js push into array if item exist 
Javascript :: obj[key].includes is not a function 
Javascript :: lip. dips *dipped. also mm bpi. -opp. -ditty 
Javascript :: javascript is object array 
Javascript :: jquery ajax delete 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =