I want to console.log
the src
attribute of any image constructed via the Image constructor on my web page. I don’t need the image when it’s loaded - just after the src attribute changes.
I’ve tried overriding the Image.onload method (This method of course gives me the later point at which the image has already loaded), but this code doesn’t console.log anything:
Image.prototype.nativeOnload = Image.prototype.onload;
Image.prototype.onload = function() {
console.log(this.src);
this.nativeOnload();
};
Perhaps this is because the onload property is overridden.
How can I detect when any image on the web page constructed via the js Image() constructor changes its source? Is there a way to do this with javascript watchers perhaps?