Detect Load Of Iframe (not Same Domain, Dynamically Added) In Javascript Or Jquery?
Is there a way to detect when an iframe is loaded in javascript / jQuery? With the following conditions: I can't control the iframe. It is added by another javascript plugin. It p
Solution 1:
Use mutation observer to detect when an iframe has been added to the DOM, then you can just add a load
event listener to detect when the iframe has laoded
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
[].filter.call(mutation.addedNodes, function (node) {
return node.nodeName == 'IFRAME';
}).forEach(function (node) {
node.addEventListener('load', function (e) {
console.log('loaded', node.src);
});
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
Post a Comment for "Detect Load Of Iframe (not Same Domain, Dynamically Added) In Javascript Or Jquery?"