Reputation: 15243
I have a function which changes content of the iframe (for instance change the URL of the images). Currently, I bind a function to iFrame's load
. Something like:
$('iframe#frame').load(function() { });
The problem is, when I run this and change the src
attribute of the iframe, the function runs after all the elements are loaded and then changes it. I want to be able to run the code as soon as the HTML content of the iFrame is loaded to prevent the extra loading time. Is there any way I can achieve this?
Upvotes: 1
Views: 4742
Reputation: 30015
Try this
$.get('https://google.com', function(data){
var doc = $frame[0].documentElement;
doc.open();
doc.write(data);
doc.close();
$frame.trigger('ijustchangedthesrc');
}, 'HTML');
later
$('iframe#frame').on('ijustchangedthesrc', function(){});
Give your iframe no src to start with.
Upvotes: 2