正在加载iframe

时间:2014-03-11 12:54:46

标签: javascript jquery html

我的网页中有两个iframe,我希望在第一个iframe加载完成后加载第二个iframe。我怎样才能做到这一点?我尝试使用settimeout函数,但遇到了一些问题。

这是我的代码:

<iframe src="firstiframe" frameborder="0" widht="100%" marginheight="0" marginwidth="0" scrolling="NO" id="the_iframe">
</iframe>  

<iframe src="secondframe" frameborder="0" widht="100%" marginheight="0" marginwidth="0" scrolling="NO"  id="the_iframe2" >
</iframe> 

<script>
function resizeIframe(iframeID) 
{    
    document.setTimeout("resizeIframe",1000);   
    var iframe = window.parent.document.getElementById(iframeID);
    var container = document.getElementById('content');
    iframe.style.height = container.offsetHeight + 'px';            
} 
</script>

3 个答案:

答案 0 :(得分:2)

您可以这样做:

$("#firstIframe").load(function (){
    $("#secondIframe").load();
});

答案 1 :(得分:2)

你可以在帧上使用jQuery ready函数来查看它何时被加载,然后为第二帧设置src url。类似的东西:

$('#firstframe').ready(function() { 
    $('#secondframe').attr('src', 'http://yourlink'); 
});

答案 2 :(得分:0)

我会用jquery做这个:

首先是iframe:

<iframe id="iframe1"></iframe>
<div id="loadsecondIframeHere"></div>
<script>
$('#iframe1').ready(function(){
    $('#loadsecondIframeHere').html('<iframe id="iframe2"></iframe');
});
</script>

或使用$(document).ready()