简体   繁体   English

无法加载 iFrame CSS

[英]Can't load iFrame CSS

I'm trying to load an iFrame into a Wordpress website.我正在尝试将iFrame 加载到 Wordpress 网站中。 The iFrame should load the table displayed in this link , with all the colors and other styles applied. iFrame 应加载此链接中显示的表格,并应用所有颜色和其他样式。

However, when I insert the iFrame on my website, it will load the content of the table but not the CSS .但是,当我在我的网站上插入iFrame时,它会加载表格的内容而不是 CSS

This is how I tried to 'force' load the right CSS, as I suspect the Wordpress theme is overriding the Table CSS:这就是我试图“强制”加载正确 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>

What am I doing wrong?我究竟做错了什么? This is my website page where the iframe is inserted (scroll to the bottom).这是我插入 iframe 的网站页面(滚动到底部)。

Use HTTPS to serve your css in the iframe.使用 HTTPS 在 iframe 中提供您的 css。 If you open the Chrome Devtools, the following error message can be seen multiple times: Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure image '<URL>'. This content should also be served over HTTPS.如果您打开 Chrome Devtools,则会多次看到以下错误消息: Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure image '<URL>'. This content should also be served over HTTPS. Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure image '<URL>'. This content should also be served over HTTPS.

First of all Iframes will not take the external css.首先,iframe 不会采用外部 css。 as they have there own html head and body tags, Its a separate html document.因为他们有自己的 html head 和 body 标签,它是一个单独的 html 文档。 you cannot override any styles in Iframe.您不能覆盖 Iframe 中的任何样式。 instead you can try attach your stylesheet in the required document and use it in the iframe.相反,您可以尝试在所需文档中附加您的样式表并在 iframe 中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM