iframe加载两次的问题


$(function(){
    var iframe = document.createElement("iframe");
    var height = document.documentElement.clientHeight - 100;
    iframe.height = height;
    iframe.name = "iframe";
    iframe.id = "iframe";
    
    iframe.width = "100%";
    iframe.frameborder = "0";
    document.getElementById("iframeDiv").appendChild(iframe);
    
    setTimeout(function(){
        iframe.src = "home.html";
    },300);
    
    /* var $iframe = '<iframe width="100%" id="iframe" name="iframe" frameborder="0" height="'+height+'>';
    $("#iframeDiv").append($iframe);
    $("#iframe").attr("src","home.html"); */
})
解决方法:先生成iframe,加入节点树,在等300ms,然后再添加src属性

猜你喜欢

转载自blog.csdn.net/qq_35232663/article/details/80837056