夜的第七章

ASP.NET、C#、.NET开发资源、Javascript等等为主的开发备注收藏注意警告等的一个个人博客。

« JavaScript 弹出窗口总结 [z]js判断数字,字母,中文 »

iframe页自适应高度问题

/*

    本js用于iframe页自适应高度问题

*/

   function iframeAutoFit()

    {

        try

        {

            if(window!=parent)

            {

                var a = parent.document.getElementsByTagName("IFRAME");

                for(var i=0; i<a.length; i++) //author:meizz

                {

                    if(a[i].contentWindow==window)

                    {

                        var h1=0, h2=0;

                        a[i].parentNode.style.height = a[i].offsetHeight +"px";

                        a[i].style.height = "0px";

                        if(document.documentElement&&document.documentElement.scrollHeight)

                        {

                            h1=document.documentElement.scrollHeight;

                        }

                        if(document.body) h2=document.body.scrollHeight;

                        var h=Math.max(h1, h2);

                        if(document.all) {h += 4;}

                        if(window.opera) {h += 1;}

                        a[i].style.height = a[i].parentNode.style.height = h +"px";

                    }

                }

            }

        }

        catch (ex){}

    }

    if(window.attachEvent)

    {

        window.attachEvent("onload",  iframeAutoFit);

        //window.attachEvent("onresize",  iframeAutoFit);

    }

    else if(window.addEventListener)

    {

        window.addEventListener('load',  iframeAutoFit,  false);

        //window.addEventListener('resize',  iframeAutoFit,  false);

    }

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Arwen Build 81206



©2007 - 2010 www.leadnt.com 保留一些权利吧