Reputation: 3200
I'm trying to catch the change of the src
attribute of an iframe
, I have found the method to catch the load
event, but if the iframe
contains some images I must wait until they are loaded before the event fires. There is a method to catch the change of the attribute instead of waiting that the pages is loaded?
Upvotes: 0
Views: 413
Reputation: 3200
I have resolved the problem with the binding to the DOMAttrModified
event
$( "#myIframe" ).bind( 'DOMAttrModified', function(){
console.log( "Attribute changed" );
});
Upvotes: 1
Reputation: 7707
Based on your comment "I've got two main methods to change the iframe src, first outside the iframe, second inside [...] problem catching the second", I think you should use the observer pattern.
You can implement it yourself, but no need for that as there's this library ( https://github.com/melanke/Watch.JS )
It's really easy to use, here's an example:
//defining a 'watcher' for an attribute
watch(exemple, "attr", function(){
alert("attr changed!");
});
I didn't used this library myself, but I use the same pattern on Angularjs (check it out in the future, it's awesome).
Hope this helps!
Upvotes: 0