简体   繁体   English

jQuery:使用html mimetype加载包含CSS样式表的html文件

[英]jQuery: load html file containing css stylesheet using html mimetype

    $.get("page/test.thml", function(html){
        $("#iframe").contents().find("html").html(html);
    },'html')

test.html contains css stylesheet. test.html包含CSS样式表。

but I get Resource interpreted as Stylesheet but transferred with MIME type text/html: 但是我将Resource interpreted as Stylesheet but transferred with MIME type text/html:

the html loads but its missing it's css styling. HTML加载,但缺少它的CSS样式。 I tried to copy paste the css file contents into the html file itself but this did not fix the issue. 我试图将css文件内容复制粘贴到html文件本身中,但这不能解决问题。

how to make the css display when the html is loaded? html加载时如何使CSS显示?

Please find below solution. 请找到以下解决方案。

<script type="text/javascript">
        $(document).ready(function () {
            // Your HTML Physical file path here// Note: style should have text/css attribute.
            $("#result").load("YourHTML.html", function () {
                alert($("#result").html()); // This is your HTML
            });
        });

    </script>

Try this: 尝试这个:

$(document).ready(function () {
  $("#result").load("file.html");
});

It will load you html including your css styling automatically(HTML with embedded CSS). 它将自动加载包含CSS样式的html(带有嵌入式CSS的HTML)。 But if you set the mapping addresses of the css file(Linked CSS case) in the html file in the right way it will be no problem. 但是,如果您以正确的方式在html文件中设置css文件(链接CSS大小写)的映射地址,那将没有问题。

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

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