Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if iFrame is loaded. ONE time. Jquery

I know there is many of possiblites when it comes to check if an iFrame content has been loaded. Although, is there anyway to limit it?

Example, if I have an iframe, and I need to check if everything has loaded, I can use the load() function. Although, if I click a NEW link inside the iframe, it will run the load() function again.

What I wish to know, is there any way to do, so jquery only checks the FIRST time the iFrame content has been loaded?

I have tried everything, nothing works.

like image 933
Oliver 'Oli' Jensen Avatar asked Aug 08 '11 10:08

Oliver 'Oli' Jensen


2 Answers

Use jquery .one, it does the unbind work for you.

$('#iframe').one('load', function() {


});

Example fiddle.

like image 99
redsquare Avatar answered Oct 17 '22 02:10

redsquare


You can unset the load callback again once it gets called.

$('#iframe').load(function() {

  // do things which are awesome

  $('#iframe').unbind('load');

});
like image 25
supakeen Avatar answered Oct 17 '22 00:10

supakeen