Ifrme自适应高度的问题 IE FireFox Opera Netscape下均测试通过

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="TY._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
        <asp:literal id="lTitle" runat="server"></asp:literal>
    </title>

    <script type="text/javascript">
    //使得FrmMain自动适应高度,不再显示Iframe中的滚动条
    function SetFrmMainheight()
    {

//纯IE使用
//       if (window.frames[0].document.body.offsetHeight > 480)
//          document.getElementById("FrmMain").style.height = window.frames[0].document.body.offsetHeight + 20;
//       else
//         document.getElementById("FrmMain").style.height = 500;

     

   var iFrm = document.getElementById("FrmMain");
        var subWeb = document.frames?document.frames["FrmMain"].document:iFrm.contentDocument;

        if (iFrm!=null&&subWeb!=null)
        {
            //if (subWeb.body.scrollHeight>480)
                iFrm.height = subWeb.body.scrollHeight+20;
            //else
            //    iFrm.height=500;
        }

    }
    </script>

    <script language="jscript" type="text/jscript" src="../Js/jsPng.js"></script>

    <style type="text/css">
     table
     {
         t1:expression(this.cellspacing=1);  
         t2:expression(this.border=0) ;
        
     }
     body
     {
     text-align:center;
     font-size:12px;
     color:#6c6f70;
     font-family:Arial;
     }
    
     </style>
</head>
<body style="background-image: url(Images/Web/page_bg.png);">
    <form id="form1" runat="server">
        <table cellpadding="0px" cellspacing="0px" style=" 941px; height: 81px; background-image: url(Images/Web/top.jpg);
            padding-left: 20px; padding-right: 20px;">
            <tr>
                <td>
                    <table style=" 890px">
                        <tr>
                            <td rowspan="2" style="text-align: left; vertical-align: middle">
                                &nbsp;<asp:Image ID="imgLogo" runat="server" /></td>
                            <td style="text-align: right; height: 30px; vertical-align: top">
                                <table border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td style="font-family: Arial">
                                            &nbsp;<asp:LinkButton ID="lbChinese" runat="server" OnClick="lbChinese_Click">简体中文</asp:LinkButton>&nbsp; | &nbsp;<asp:LinkButton ID="lbEnglish" runat="server" OnClick="lbEnglish_Click">English</asp:LinkButton>
                                            &nbsp; &nbsp;&nbsp; &nbsp;</td>
                                        <td>
                                            <asp:TextBox ID="tbSearch" runat="server" Style="border-right: #9c9c9c 0px solid;
                                                border-top: #9c9c9c 1px solid; border-left: #9c9c9c 1px solid; border-bottom: #9c9c9c 1px solid;
                                                120px;" Height="14px" ForeColor="Gray"></asp:TextBox>
                                        </td>
                                        <td>
                                            <asp:ImageButton ID="ibSearch" runat="server" ImageUrl="./Images/Web/search.png" OnClick="ibSearch_Click" /></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: right">
                                <asp:Menu ID="mNavigate" runat="server" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False"
                                    MaximumDynamicDisplayLevels="1" Width="450px">
                                </asp:Menu>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <div>
            <table  cellpadding="0px"  cellspacing="0px"  style=" 941px">
            <tr>
                <td   style="background-image:url(Images/Web/left.jpg); 5px">
                </td>
                <td valign="top">
                   <iframe id="FrmMain" width="100%" enableviewstate="true" name="FrmMain" frameborder="0" 
                            scrolling="no" onload="SetFrmMainheight();" src="./Web/FrmMain.aspx"></iframe>
                </td>
                <td style="background-image:url(Images/Web/right.jpg); 5px">
                   
                </td>
            </tr>
        </table>
                   </div>
    </form>
</body>
</html>

原文地址:https://www.cnblogs.com/pchgo/p/1423924.html