本地文件上的 Internet Explorer“由于 MIME 类型不匹配而忽略 CSS”(无服务器)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16473610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:49:21  来源:igfitidea点击:

Internet Explorer "CSS was ignored due to mime type mismatch" on local files (no server)

cssinternet-explorerweb

提问by Mattisdada

I'm developing an application which creates a HTML report at the end, it outputs the js and css files separately then loads the files normally. But Internet Explorer 8-10+ refuses to load the CSS files due to "CSS was ignored due to mime type mismatch", but of course, the MIME can't be modified, as they are local files and notbeing served by a server.

我正在开发一个应用程序,它在最后创建一个 HTML 报告,它分别输出 js 和 css 文件,然后正常加载文件。但是 Internet Explorer 8-10+ 拒绝加载 CSS 文件,因为“由于 MIME 类型不匹配CSS 被忽略”,当然,MIME 不能被修改,因为它们是本地文件,不是由服务器提供的.

So in short:

简而言之:

  • Local files (C:\,file://,etc)
  • CSS Won't load due to "MIME type mismatch"
  • Works in every other browser without issue -_-
  • Not "http://" or "localhost" or any variant
  • 本地文件(C:\、file:// 等)
  • 由于“MIME 类型不匹配”,CSS 无法加载
  • 可以在所有其他浏览器中正常工作-_-
  • 不是“http://”或“localhost”或任何变体

So, does anyone have any idea's on a work-around for this issue?

那么,有没有人对这个问题的解决方法有任何想法?

HTML loading of CSS:

CSS 的 HTML 加载:

<head>
    <title>Results</title>
    <link href='resources/bootstrap.min.css' rel='stylesheet' type='text/css' />
    <link href='resources/bootstrap-responsive.min.css' rel='stylesheet' type='text/css' />
    <link href='resources/style.css' rel='stylesheet' type='text/css' />
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>    
</head>

Note: According to Microsoft, the fix is: "Ensure style sheet file is delivered with the proper HTTP response header, which includes a content type of text\css. See MIME-Handling Changes in Internet Explorer for more information.", but obviously impossible, as no header's are being sent across the wire......

注意:根据Microsoft 的说法,修复方法是:“确保使用正确的 HTTP 响应标头传送样式表文件,其中包括 text\css 的内容类型。有关详细信息请参阅 Internet Explorer 中的 MIME-Handling Changes。”,但显然不可能,因为没有标题通过线路发送......

采纳答案by Mattisdada

Found out the issue by testing on a few different machines, it turns out if you have a CSS file set to open with a particular program, it will prevent IE from loading, and will give the above error message -_-

通过在几台不同的机器上测试发现了问题,结果是如果您将 CSS 文件设置为使用特定程序打开,它将阻止 IE 加载,并会给出上述错误消息 -_-

Also mitigating the potential problem by including a CDN version of the CSS at the end of the file (the report has to work with and without internet)

还通过在文件末尾包含 CSS 的 CDN 版本来缓解潜在问题(报告必须在有和没有互联网的情况下工作)

回答by user3781952

I'm on Windows 8.1 using IE11 with the same issue. This is how I fixed it:

我在使用 IE11 的 Windows 8.1 上遇到同样的问题。这是我修复它的方式:

  1. On your computer search for "regedit.exe" (go to the start menu and click on the search button on the top-right corner of the screen).
  2. Once regedit opens up, on the left column click on "HKEY_CLASSES_ROOT" and then on ".css"
  3. On the right column double-click on "Content Type". This will open up a dialog box.
  4. In the dialog box change "value data" to "text/css".
  5. Click "Ok" and that's it.
  1. 在您的计算机上搜索“regedit.exe”(转到开始菜单并单击屏幕右上角的搜索按钮)。
  2. 打开 regedit 后,在左栏中单击“HKEY_CLASSES_ROOT”,然后单击“.css”
  3. 在右栏中双击“内容类型”。这将打开一个对话框。
  4. 在对话框中将“值数据”更改为“text/css”。
  5. 单击“确定”,就是这样。

I hope this helps other people out there.

我希望这可以帮助其他人。

回答by user1052080

I was using Tomcat and JSP. I had to put : <%@page contentType="text/css" %> at the top of the CSS file and then tomcat serves it as a CSS mimetype.

我使用的是Tomcat和JSP。我不得不将: <%@page contentType="text/css" %> 放在 CSS 文件的顶部,然后 tomcat 将其用作 CSS mimetype。

回答by Tesfaye Hillo wojago

In my case, the folder where CSS hosted had different permission than page where CSS needed to be applied. I changed to same permission and worked.

就我而言,托管 CSS 的文件夹与需要应用 CSS 的页面具有不同的权限。我更改为相同的权限并工作。

回答by Dionysios

Kyeemagh, 23 May -14

凯马,5 月 23 日 -14 日

Hi to all of you who have the problem with Internet Explore that showing "CSS was ignored due to mime type mismatch" on local files (no server).

大家好,Internet Explorer 的问题是在本地文件(无服务器)上显示“由于 MIME 类型不匹配,CSS 被忽略”。

I have Win7 with IE11 and i found the solution by doing 2 days searching in the Internet... with many coffees.

我有带 IE11 的 Win7,我通过在互联网上搜索 2 天找到了解决方案......有很多咖啡。

Please click on the first link then scroll down to the "3 Answers" and read the instructions how to solve the problem! In my laptop works ok.

请点击第一个链接,然后向下滚动到“3 个回答”并阅读如何解决问题的说明!在我的笔记本电脑上工作正常。

CSS not rendered in IE 10

CSS 未在 IE 10 中呈现

and then for original information and ownership click on:

然后对于原始信息和所有权,请单击:

http://nirsoft.net/utils/file_types_manager.html

http://nirsoft.net/utils/file_types_manager.html

I hope it helps.

我希望它有帮助。

Eventually I can see correctly all my web pages that I'm making, from my C: driver - no server, on the IE11 browser.

最终,我可以在 IE11 浏览器上正确地看到我正在制作的所有网页,从我的 C: 驱动程序 - 没有服务器。

Remember to have the correct coding in your html page at section, that link to an external css file.

请记住在您的 html 页面中的部分中有正确的编码,该链接指向外部 css 文件。

  • Please pass it to anyone who need this particular free help!
  • 请将它传递给任何需要这种特殊免费帮助的人!

with many thanks,

非常感谢,

Dionysios

狄奥尼修斯