Skip to content Skip to sidebar Skip to footer

Load An Iframe Once Another Iframe Has Finished Loading

I have multiple iframe tags in a webpage, but I would like them not to load all at once. Meaning, I want iframe1 to start loading once the page is opened, then when it's completely

Solution 1:

Use html like this:

<iframe id="iframe1" data-src="..."></iframe>
<iframe id="iframe2" data-src="..."></iframe>
<iframe id="iframe3" data-src="..."></iframe>

and js:

$(function() {
  var iframes = $('iframe');
  var i = 0;
  (functionnext() {
      var iframe = iframes.eq(i++);
      if (iframe.length) {
          iframe.attr('src', iframe.data('src')).load(next);
      }
  })();
});

Post a Comment for "Load An Iframe Once Another Iframe Has Finished Loading"