日期:2014-05-20  浏览次数:20783 次

求救一个iframe嵌入网页后的高度问题!
C# code


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function (){
            var iframe = document.getElementById("userArea");
            try {
                var bHeight = iframe.contentWindow.document.body.scrollHeight;
                var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
                var height = Math.max(bHeight, dHeight);
                iframe.height = height;
            } catch (ex) { }
        });  

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <iframe  id="userArea" name="userArea" frameborder="0" style="width:100%;" src="http://www.baidu.com"   ></iframe>
    </div>
    </form>
</body>
</html>




我这样写,怎么没有用,高度还是一点点,我想得是,随网页的高度变化而变化!

------解决方案--------------------
http://www.ccvita.com/376.html
------解决方案--------------------
<iframe ... marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0>
在嵌入的页面加CSS
html,body{margin:0px; padding:0px}
------解决方案--------------------
<iframe frameborder="0" id="Right" name="Right" scrolling="yes" src="Main.aspx" style="width:100%;height:100%;" > </iframe>
<script>
function setAutoHeight(iframeElement, dheight) {

iframeElement.style.height =dheight ; 

}
setAutoHeight(document.getElementById("Right"), window.document.documentElement.clientHeight +"px");
</script>
------解决方案--------------------
document.documentElement.clientHeight
------解决方案--------------------
http://www.jb51.net/article/15780.htm
------解决方案--------------------
iframe.style.height = height+"px";