Delay load of iframe?

后端 未结 10 1575
悲哀的现实
悲哀的现实 2021-02-19 06:15

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 fini

相关标签:
10条回答
  • 2021-02-19 06:30
    window.setTimeout(function(){   
    $("#myframe").attr("src","exp3.html");
    $("#myframediv").show("slow");
    },4000);
    

    try this, this also works.

    0 讨论(0)
  • 2021-02-19 06:31

    You can also apply display:none to the iframe with CSS, then use jQuery's .show like this:

    $(document).ready(function(){ 
        $('iframe.class_goes_here').show(); 
    });
    
    0 讨论(0)
  • 2021-02-19 06:34

    Or my favorite use

    setTimeout('your app', 6000)
    

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

    0 讨论(0)
  • 2021-02-19 06:41

    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

    0 讨论(0)
  • 2021-02-19 06:44

    This works for me, but has problems if you change the code at all:

    function loadIFrame() {
        window.frames['BodyFrame'].document.location.href = "iframe.html";
    }         
    function delayedLoad() {
        window.setTimeout(loadIFrame2, 5000);
    }
    

    Using:

    <iframe src="" onLoad="delayedLoad()"></iframe>
    
    0 讨论(0)
  • 2021-02-19 06:45

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

    0 讨论(0)
提交回复
热议问题