首页 > 技术文章 > 解决IE6下JS动态插入iframe不显示的方法

mixzo 2015-01-09 16:20 原文

function myshowBox(titles, urls, objWidth, objHeight, flags)
{
    var _title = titles;
    var _url = urls;
    var _width = objWidth;
    var _height = objHeight;
    var _flag = flags;
 
    $("body").append("<div class='myshowbox'><div class='myshowbox-container'><a class='btn-close' href='javascript:;'></a><h3>" + _title + "</h3><iframe class='iframe-myshowbox' id='myshowbox' src='" + _url + "' frameborder='0' scrolling='no' width='" + _width + "' height='" + _height + "'></iframe></div></div><div id='bgScreen'></div><iframe id='bgIFrame' src='about:blank'></iframe>");
    //判断是否有标题
    if (_title == "")
    {
        $(".myshowbox h3").hide();
    }
    else
    {
        $(".myshowbox h3").css("width", _width - 20 + "px");
    }
    $(".myshowbox-container").css("width", _width);
    $(".myshowbox").css("margin", -$(".myshowbox").height() / 2 - 5 + "px 0 0 " + -$(".myshowbox").width() / 2 + "px");
    $("#bgScreen, #bgIFrame").css("height", $("body").height() + "px");
 
    //关闭释放
    $(".myshowbox-container .btn-close, #bgScreen").live('click', function()
    {
        $(".myshowbox, #bgScreen, #bgIFrame").hide().remove();
    })
 
    //IE6 BUG fix
    var ieset = navigator.userAgent;
    if (ieset.indexOf("MSIE 6.0") > -1)
    {
        setTimeout('window.parent[\'myshowbox\'].location.reload();', 0);
    }
}
 

推荐阅读