I have almost the same case. But in my case, I want to exclude all iframes downloading content from another site (e.g. youtube, vimeo, etc.). The job was found, so the script is the hide 'src' attribute from all iframes when the DOM is ready and returns it when the window ends, loads all other content.
(function($){ //DOM is ready $(document).ready(function(){ var frame = $('iframe'), frameSrc = new Array(); if( frame.length ){ $.each( frame, function(i, f){ frameSrc[i] = $(f).attr('src'); //remove the src attribute so window will ignore these iframes $(f).attr('src', ''); }); //window finish load $(window).on('load',function(){ $.each( frame, function(a, x){ //put the src attribute value back $(x).attr('src', frameSrc[a]); }); }); } }); })(jQuery);
You can mark all the elements of your site that load external resources by adding a special class and changing the iframe with $('.special_class') or something like that. I don't know if this is the best, but at least it works fine on my side: D
source share