【问题标题】:iframe weirdnessiframe 怪异
【发布时间】:2012-11-15 16:32:28
【问题描述】:

我有两个网站,我正在将它们融合在一起。我正在使用 iframe 来显示另一页面中的内容,就好像它们都是一个站点一样。这里需要注意的是,当在 iframe 中查看时,我需要页面正常显示,否则显示警告。由于 IIS 不兼容,我无法将 iframe 页面导入主机页面,因此该选项已失效。当我在所有情况下都简单地显示页面时,该计划运行良好,当我尝试实现条件显示时,我遇到了问题。在 iframe 页面上,我有以下内容:

<script type="text/javascript">
    window.onload = function InFrame() {
        MainContent_siteIsNotFramed
        if (top != self) {
            //document.getElementById("siteIsFramed").style.display = "inline"
            siteIsFramed.visible = "true"
        }
        else {
            //document.getElementById("MainContent_siteIsNotFramed").style.display = "inline"
            siteIsNotFramed.visible = "true"
        }
        init();
    };
</script>

这是我尝试让 iframe 页面处理自己的条件显示。我在主机页面中唯一相关的代码是 iframe 本身,为了完整起见,它看起来像这样:

</head>
<body style="margin:0; height: 100%;">

<iframe  runat="server" id="signInFrame" style="border: 0; width: 100%; height: 100%; ">
    Your browser does not support iframes. Consider upgrading.
</iframe>
</body>
</html>

当内容显示/不显示时,iframe 中的内容将显示大约一半的高度。没有,它会以全高显示(期望的行为)。我已经尽量做到了,如果有人需要更多细节,请告诉我。

【问题讨论】:

    标签: javascript html iframe height


    【解决方案1】:

    尝试“定位” iframe:

    <iframe  runat="server" id="signInFrame" style="border: 0; position:absolute; width: 100%; height: 100%; ">
       Your browser does not support iframes. Consider upgrading.
    </iframe>
    

    问题在于,具有默认位置(位置:静态)的 iframe 不能有“相对”高度(即 %),因此它会忽略高度:100%,并应用“默认”高度iframe(FF 中为 150 像素)。

    【讨论】:

    • 这也不行。我似乎无法弄清楚问题出在 iframe 还是我试图在 iframe 页面中显示/隐藏的 div 上。
    • 当网站未显示在 iframe 中而不是显示/隐藏两个 div 时,我决定简单地重定向到错误页面。没有包装 div,页面在 iframe 中显示得很好。不过感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2012-10-28
    • 2014-09-17
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多