100%高度的iframe在ie7中显示错误,原因是iframe.style.height="100%"。
在网上搜到很多iframe自适应高度的文章。我们只需要让iframe的高度跟浏览器显示区域的高度一样就行了,跟iframe自适应高度是不一样的。
下面使用js实现iframe中的高度和浏览器的高度一样。
- <script type="text/javascript">
- function htmlH() {
- document.getElementById("menu").style.height = screen.availHeight;
- document.getElementById("iframe1").style.height = screen.availHeight;
- document.getElementById("right").style.height = screen.availHeight;
- }
- </script>
- </head>
- <body style="margin-top:1px; margin-left:0px; margin-bottom:1px;" οnlοad="htmlH()">
- <form id="form1" runat="server" >
- <div>
- <asp:ScriptManager ID="ScriptManager1" runat="server">
- </asp:ScriptManager>
- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
- <ContentTemplate>
- <iframe id="menu" name="menu" src="menu.aspx" width="13%" frameborder="0" marginheight="0"></iframe>
- <iframe id="Iframe1" src="b.aspx" width="4px" frameborder="0" marginheight="0" style="" scrolling="no"></iframe>
- <iframe id="right" name="R1" src="index.aspx" width="86.5%" frameborder="0" marginheight="1" marginwidth="1" runat="server" style="margin:0;"></iframe>
- <br />
- </ContentTemplate>
-
- </asp:UpdatePanel>
-
- </div>
- </form>
- </body>
- </html>
本文有三个iframe,所以在js中得写三个,根据自己需要进行改变!