views:

929

answers:

4

Hello All-

I know there are some tools and techniques for delaying the load of javascript, but I have an iframe that I would like to delay loading until after the rest of the page has finished downloading and rendering (the iframe is in a hidden that will not be revealed until someone clicks on a particular tab on the page. Is there a way to delay the load of an iframe? Any suggestions would be much appreciated. Thanks!

+2  A: 

Use Javascript in the onLoad event, or in the button click handler, to set the src attribute of the iframe.

devio
+1  A: 

with jquery it is easy!

either enclose your code which loads the iframe within a $() or use $(document).ready(function(){}) these both are the same and would execute your code after the DOM is ready!

e.g.

$(document).ready(function(){
    $('iframe#iframe_id').attr('src', 'iframe_url');    
});

see more at http://www.learningjquery.com/2006/09/introducing-document-ready

Tzury Bar Yochay
It turns out your first line solved everything. I was using a horrible template for tabs that I downloaded from a random website, and it liked to render my hidden iframe in front of everything unti it fully loaded. When I switched over to using jquery tabs (which looked much nicer to boot!), the iframe rendering was no longer an issue. jQuery ROCKS!Thanks :)
Sean
A: 

or my favorite use SetTimeOut('your app',6000)

That will make it wait x number of seconds to call any function....

crosenblum
+1  A: 

Dont know if need do run without javascript. But the best methode is do change the src direct after the iframe:

<iframe id="myIframe" src="http://.." />
<srcipt type="text/javascript">
  var iframe = document.getElementById('myIframe'),scr = iframe.src;
  iframe.src = '';
  document.onload =  function(){iframe.src = src;})
</script>

Using $(document).ready will start the rendering of your Iframe direct after the DOM Tree is build, but before all of the content in your side is loaded, so I think this isn't what you want.

eskimoblood
Hey Eskimo-I assume your answer would work, although I wasn't able to make it work (I'm sure it was due to a problem on my end) :) I don't have enough reputation to vote you up yet, but thanks for the suggestion!
Sean