2014-10-06 96 views
1

我在頁面上加載了iframe。 iframe的內容只在內容的其餘部分加載到頁面後才加載。是否可以在主頁面上的其餘內容之前加載iframe中的內容?在其他內容之前加載iframe

感謝

+0

iframe的內容來自哪裏? – Alex 2014-10-06 14:33:13

+0

它來自子域。主域名是一個WordPress站點,它從一個子域名上的網站中抽取一個表格 – user2753924 2014-10-06 14:37:26

+0

你可以嘗試在jsfiddle上發佈一些內容嗎? – Alex 2014-10-06 14:39:42

回答

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

0

嘗試

// 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/

jQuery.holdReady()