动态更改iframe src

最近使用iframe 做项目,在动态更改Src的时候,要么IE6 IE7支持 要么Chrome不支持。崩溃中。

没有办法只能使用最简单的判断办法,重复造轮子吧。

        function ChangeIframeSrc(url) {
            $("#RightTD_setup", window.parent.document).html('<iframe frameborder="0" name="RightContent" id="RightContent"  style="margin:0px; padding:0px;"  scrolling="no" width="100%"     src="' + url + '" allowTransparency="true"></iframe>');
            if ($("#RightContent", window.parent.document).contents().find("body").height() == undefined) { //针对IE6,7,8单独做
                window.parent.document.getElementById('RightTD_setup').innerHTML = "";
                var el = document.createElement("iframe");
                el.id = "RightContent";
                el.scrolling = "no";
                el.allowTransparency = "true";
                el.src = '' + url + '';
                el.frameBorder = "0";
                window.parent.document.getElementById('RightTD_setup').appendChild(el);
            }
            $("#RightContent", window.parent.document).css("width", "670px");
            var marginheiht = 0;
            marginheiht = $("#RightContent", window.parent.document).contents().find("body").height()
            if (marginheiht < 550) {
                marginheiht = 550;
            }

            $("#RightContent", window.parent.document).height(marginheiht);
        }

呵呵代码很丑陋,刚刚测试成,目前修改中,希望路过的大牛,帮忙解决下,不再重复造轮子

原文地址:https://www.cnblogs.com/flyfish2012/p/3049610.html