2

I have an iframe loading on my page. The content of the iframe only loads after the rest of the content has loaded on the page. Is it possible to load the content within the iframe before the rest of the content on the main page?

Thanks

user2753924
  • 405
  • 4
  • 14
  • where's the content of the iframe coming from? – Alex Oct 06 '14 at 14:33
  • Its coming from a sub domain. The main domain is a wordpress site and its pulling in a form from a website on a sub domain – user2753924 Oct 06 '14 at 14:37
  • Could you try and post something on jsfiddle? – Alex Oct 06 '14 at 14:39
  • you can have display:none in your parent page except the iframe and when iframe finishes loading you need to communicate with parent page (http://stackoverflow.com/questions/9153445/how-to-communicate-between-iframe-and-the-parent-site) and reveal parent site content by removing display:none – Sharky Oct 06 '14 at 14:43
  • Isn't there a way of forcing the iframe to load first with javascript? – user2753924 Oct 06 '14 at 14:57

2 Answers2

1
    <iframe id="miiframe" src="http://www.apple.com"></iframe>
    <!-- example -->
    <div id="loading" style="position:fixed;background:red;width:100%;height:100%;top:0;left:0;z-index:2;"></div>
    <img id="background" style="position:absolute;width:100%;height:100%;top:0;left:0;z-index:-1;"/>

<script>
var loaded = false;
console.log(loaded);
function preloader(){
            document.getElementById("loading").style.display = "none";
            document.getElementById("miiframe").style.display = "block";
    loaded = true;
            console.log(loaded);
}//preloader
var loadiframe = document.getElementById('miiframe');
loadiframe.onload = preloader;

if(!loaded){
    window.onload = function(){
        background = document.getElementById("background");
        background.src ="http://www.hdwallpapers.in/walls/cute_baby_in_autumn-wide.jpg";
    };
}
</script>

see JSFIDDLE

alessandrio
  • 3,901
  • 2
  • 27
  • 36
0

Try

// hold `ready` event
$.holdReady(true);

var frame = $("<iframe>");

$(frame).load(function(e) {
    // release `ready` event
    $.holdReady(false)
});

// append `frame` to document
$("body").append(frame);

$(document).ready(function() {
  // do stuff 
  // after `frame` loaded
  $("body").append("done")
});

jsfiddle http://jsfiddle.net/guest271314/x7ptnbjy/

See jQuery.holdReady()

guest271314
  • 1
  • 10
  • 82
  • 156