Answers for "how to add event listener to iframe"

1

how to add event listener to iframe

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

function Handler() {
    alert('works');
}
Posted by: Guest on July-18-2020
0

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');
                });
};
Posted by: Guest on August-24-2020

Code answers related to "how to add event listener to iframe"

Code answers related to "Javascript"

Browse Popular Code Answers by Language