【问题标题】:Can't load iFrame CSS无法加载 iFrame CSS
【发布时间】:2018-10-29 21:13:55
【问题描述】:

我正在尝试将 iFrame 加载到 Wordpress 网站中。 iFrame 应加载显示在this link 中的表格,并应用所有颜色和其他样式。

但是,当我在我的网站上插入 iFrame 时,它会加载表格的内容而不是 CSS。。 p>

这就是我尝试“强制”加载正确 CSS 的方式,因为我怀疑 Wordpress 主题覆盖了表格 CSS:

<script language="javascript" type="text/javascript">
    function iFrameHeight() {
var h = 0;
if (!document.all) {
    h = document.getElementById('blockrandom').contentDocument.height;
    document.getElementById('blockrandom').style.height = h + 60 + 'px';
} else if (document.all) {
    h = document.frames('blockrandom').document.body.scrollHeight;
    document.all.blockrandom.style.height = h + 20 + 'px';
    var cssLink1 = document.createElement("link");
    cssLink1.href = "https://www.gscris.it/lmo/lmo-style.css";
    cssLink1.rel = "stylesheet";
    cssLink1.type = "text/css";
    frames['iframe'].document.head.appendChild(cssLink1);
    var cssLink2 = document.createElement("link");
    cssLink2.href = "https://www.gscris.it/lmo/lmo-style-nc.css";
    cssLink2.rel = "stylesheet";
    cssLink2.type = "text/css";
    frames['iframe'].document.head.appendChild(cssLink2);
    }
}
    </script>
    <div>Campioni d'amicizia</div>
        <iframe onload="iFrameHeight()" id="blockrandom" name="iframe" src="https://www.gscris.it/lmo/lmo.php?todo=&file=Piccamici201819.l98" width="100%" height="600" scrolling="no" align="top" frameborder="0">
    Questa scelta non funziona correttamente in quanto il browser utilizzato non supporta gli Inline Frames     </iframe>

我做错了什么? 这是我的website page,其中插入了 iframe(滚动到底部)。

【问题讨论】:

    标签: javascript html css iframe


    【解决方案1】:

    使用 HTTPS 在 iframe 中提供您的 CSS。如果打开 Chrome Devtools,会多次看到如下错误信息:Mixed Content: The page at '&lt;URL&gt;' was loaded over HTTPS, but requested an insecure image '&lt;URL&gt;'. This content should also be served over HTTPS.

    【讨论】:

    • 是的,应该是这个原因,现在试试,会告诉你的
    【解决方案2】:

    首先,iframe 不会采用外部 css。因为他们有自己的 html 头和身体标签,它是一个单独的 html 文档。您不能覆盖 iframe 中的任何样式。相反,您可以尝试将样式表附加到所需文档中并在 iframe 中使用。

    【讨论】:

    • 哦,感谢您对我的覆盖疑问的澄清。但是我非常有信心根本问题是我尝试导入的 CSS 不使用 HTTPS,将尝试解决此问题并很快更新
    猜你喜欢
    • 1970-01-01
    • 2016-10-19
    • 1970-01-01
    • 1970-01-01
    • 2019-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多