IE9阻止跨源Web字体下载

发布于 2024-10-18 04:01:34 字数 660 浏览 3 评论 0原文

这让我发疯。

刚刚在 IE9 上测试一个网站,发现“实时”版本正在渲染我正在使用的网络字体,该字体比开发版本小。

以下是屏幕截图的选择:

在此处输入图像描述

我正在使用 Font Squirrel @font-face 套件。正如您所看到的,在 Firefox、Chrome 甚至 IE9 上查看该网站的本地版本时都没有问题。

本地版本和实时版本之间的唯一区别是字体是从实时站点上的不同域加载的(我已经正确设置了跨域策略,正如它在 Firefox 和 Chrome 上运行的事实所说明的那样)。

我不记得它在 IE8 中的样子(微软再次没有想到开发人员,并且在 IE8 之上安装了 IE9,并且没有同时运行它们的选项)

该站点位于 http://enplanner.com 这样您就可以查看源代码。

对此的任何帮助将不胜感激 - 提前谢谢您。

编辑:我已经删除了 IE9,发现它在本地和 IE8 中看起来完全相同。看来 IE8 拥有更优秀的渲染引擎,比 IE9 更接近 FF/Chrome。这是一个相当令人沮丧的发现。

This is driving me crazy.

Just testing a site on IE9 and discovered that the 'live' version is rendering a web font I am using smaller than on the dev version.

Here is a selection of screen grabs:

enter image description here

I am using the Font Squirrel @font-face kit. As you can see, it is fine on Firefox, Chrome and even IE9 when viewing a local version of the site.

The only difference between the local and live versions is that the font is being loaded from a different domain on the live site (I have set up the cross-domain policy correctly, as illustrated by the fact it works on Firefox and Chrome).

I can't remember what it looked like in IE8 (Microsoft, yet again, haven't thought of developers and have installed IE9 over the top of IE8 with no option to run them simultaneously)

The site is at http://enplanner.com so you can view the source.

Any help on this would be most appreciated - thank you in advance.

Edit: I have removed IE9 and discovered that is looks exactly the same on both local and live in IE8. It appears IE8 has a superior rendering engine that is closer to FF/Chrome than IE9. This is quite a depressing discovery.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

浮华 2024-10-25 04:01:34

IE9支持.WOFF; IE8 不支持,并且仅支持 .EOT 字体。

打开 IE9 F12 开发者工具,您会看到以下消息:

CSS3117: @font-face failed cross-origin request. Resource access is restricted. 
Neuton-webfont.woff

CSS3117: @font-face failed cross-origin request. Resource access is restricted. 
YanoneKaffeesatz-Regular-webfont.woff

CSS3114: @font-face failed OpenType embedding permission check. Permission must be Installable. 
Neuton-webfont.ttf

CSS3114: @font-face failed OpenType embedding permission check. Permission must be Installable. 
YanoneKaffeesatz-Regular-webfont.ttf

检查您的 HTTP 标头,很明显您的跨域访问配置不正确,因为没有 Access-Control-Allow-Origin 响应WOFF 文件的标头。它们还以错误的 MIME 类型 (text/plain) 交付,尽管这不会导致您的问题。但是,未能将 woff 映射到正确的 MIME 类型可能会导致问题,因为某些服务器不会提供具有“未定义”扩展名的文件,而是返回 HTTP/ 404错误。

IE9 supports .WOFF; IE8 does not, and supports only .EOT fonts.

Open the IE9 F12 Developer Tools and you see the following messages:

CSS3117: @font-face failed cross-origin request. Resource access is restricted. 
Neuton-webfont.woff

CSS3117: @font-face failed cross-origin request. Resource access is restricted. 
YanoneKaffeesatz-Regular-webfont.woff

CSS3114: @font-face failed OpenType embedding permission check. Permission must be Installable. 
Neuton-webfont.ttf

CSS3114: @font-face failed OpenType embedding permission check. Permission must be Installable. 
YanoneKaffeesatz-Regular-webfont.ttf

Examining your HTTP headers, it's clear that your cross-domain access is not configured properly, as there is no Access-Control-Allow-Origin response header on your WOFF files. They're also delivered with the wrong MIME type (text/plain) although that's not causing your problem. However, failure to map woff to the correct MIME type can cause problems as some servers will not serve files with "undefined" extensions and will instead return a HTTP/404 error.

度的依靠╰つ 2024-10-25 04:01:34

好的,这就是有效的方法。将以下部分放入您提供字体的主机的 Apache 配置中:

<FilesMatch "\.(ttf|otf|eot|woff)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "http://mydomain.example"
    </IfModule>
</FilesMatch>

mydomain.example 替换为您自己的域或 * (但要小心使用 < code>* 因为这意味着任何人都可以使用您的 CDN)

|woff 是我忘记的。哎哟!

OK, here's what worked. Place the following section in your Apache config for the host you're serving the fonts from:

<FilesMatch "\.(ttf|otf|eot|woff)
quot;>
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "http://mydomain.example"
    </IfModule>
</FilesMatch>

Replace mydomain.example with either your own domain or * (but be careful using * as this means anyone can use your CDN)

The |woff was what I'd forgotten. Doh!

黯然 2024-10-25 04:01:34

对于上面meanstreakuk的回答,我想补充一下。
我们遇到了同样的问题,我们搜索了 Google Web Font 的功能。
所以,我们输入 htaccess:

标头设置 Access-Control-Allow-Origin "*"

instead of our domain.
If the asterisc, as Google does, it works all the time.

Regarding the answer of meanstreakuk above, I'd like to complement.
We had the same problem and we searched what Google Web Font does.
So, we put in our htaccess, this:

Header set Access-Control-Allow-Origin "*"

instead of our domain.
If the asterisc, as Google does, it works all the time.

美人迟暮 2024-10-25 04:01:34

对于 IIS 添加下面的行....就像一个魅力


<system.webServer>
          <httpProtocol>
          <customHeaders>
              <add name="Access-Control-Allow-Origin" value="*" />
              <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
              <add name="Access-Control-Allow-Headers" value="Content-Type" />
          </customHeaders>
      </httpProtocol>
  </system.webServer>

For IIS Add the lines below....works like a charm


<system.webServer>
          <httpProtocol>
          <customHeaders>
              <add name="Access-Control-Allow-Origin" value="*" />
              <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
              <add name="Access-Control-Allow-Headers" value="Content-Type" />
          </customHeaders>
      </httpProtocol>
  </system.webServer>
溺孤伤于心 2024-10-25 04:01:34

我找到了一种解决方法。将其添加到 htaccess 中。

BrowserMatch MSIE best-standards-support
Header set X-UA-Compatible IE=8 env=best-standards-support

I found one workaround. Added this to htaccess.

BrowserMatch MSIE best-standards-support
Header set X-UA-Compatible IE=8 env=best-standards-support
亚希 2024-10-25 04:01:34

使用 Access-Control-Allow-Origin 标头的另一种解决方案是使用 data: 将字体嵌入到 CSS 中。

An alternative solution to using the Access-Control-Allow-Origin header is to embed the font in your CSS using data:.

很糊涂小朋友 2024-10-25 04:01:34

检查是否可以在 IE 中打开该文件 (your-web.example/your-font.woff),如果收到错误 404,请转到 IIS,双击“MIME 类型”配置选项,同时在左侧面板中选择 IIS 根节点,然后单击右侧操作面板中的“添加...”链接。这将弹出以下对话框。添加 .woff 文件扩展名,并指定 application/x-font-woff 作为相应的 MIME 类型。

我在本网站 (Robòtica educativa) 中使用此说明,我将原始 < code>.ttf 字体 (http://www.font2web.com/)

Check if you can open in IE the file (your-web.example/your-font.woff), If you receive error 404 go to IIS, double-click the "MIME Types" configuration option while having IIS root node selected in the left panel and click "Add..." link in the Actions panel on the right. This will bring up the following dialog. Add .woff file extension and specify application/x-font-woff as the corresponding MIME type.

I use this instructions in this site (Robòtica educativa), I convert my original .ttf font on (http://www.font2web.com/)

无言温柔 2024-10-25 04:01:34

还值得注意的是,如果您的资产托管在 Amazon AWS S3 上,您将无法设置服务器发送的标头。相反,您需要按照以下说明在存储桶上配置 CORS 设置:

It's also worth noting that if your assets are hosted on Amazon AWS S3 that you won't be able to set the headers that the server sends. Instead, you will need to configure the CORS settings on your bucket, as per these instructions:

吾家有女初长成 2024-10-25 04:01:34

不要忘记包含 .svg - 这在某些情况下可能是必要的。添加它解决了 IE 11 中的问题

<FilesMatch "\.(eot|otf|svg|woff|ttf)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>

Don't forget to include .svg -- this can be necessary in some instances. Adding it solved the problem in IE 11

<FilesMatch "\.(eot|otf|svg|woff|ttf)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>
欢烬 2024-10-25 04:01:34

要在 ASP.Net 中实现,您可以使用以下语法

Response.AppendHeader("Access-Control-Allow-Origin", "*");

To implement in ASP.Net you can use this syntax

Response.AppendHeader("Access-Control-Allow-Origin", "*");
下雨或天晴 2024-10-25 04:01:34

我尝试了一切方法,包括修改我的 apache 配置和 .htaccess 文件,但没有成功。在IE开发工具中我偶然发现了“文档模式”,默认是IE7。因此,经过一些研究,我发现了这个元标记:

<meta http-equiv="X-UA-Compatible" content="IE=9">

现在 IE 10 和 9 可以正确格式化我的网站并正确显示所有 Font Awesome 图标。

希望有帮助...

I tried everything from modifying my apache config, and .htaccess files with no luck. In the IE development tools I stumbled upon "Document Mode" and the default was IE7. So after some research I found this meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=9">

Now IE 10, and 9 format my website correctly and display all Font Awesome icons correctly.

Hope that helps...

桜花祭 2024-10-25 04:01:34

未经测试!
Nginx 站点文件位,如果您的 CDN 不是公开的,则仅允许原始访问字体文件:-) 快乐编码

location ~ \.(ttf|otf|eot|woff)$ { 
    Access-Control-Allow-Origin: * 
}

NOT TESTED!
Nginx site file bit for allowing just origin access to font files if your CDN is not public :-) Happy coding

location ~ \.(ttf|otf|eot|woff)$ { 
    Access-Control-Allow-Origin: * 
}
当梦初醒 2024-10-25 04:01:34

在控制台 (F12) 中注意到此错误后:@font-face 跨源请求失败。资源访问受到限制 我发现我的浏览器(IE11,仿真:IE9)“阻止了内容以帮助保护我的隐私”。通过解锁内容 - 单击网址旁边的标志 - 它可以正常工作。

After noticing this error in the console (F12): @font-face failed cross-origin request. Resource access is restricted I discovered that my browser (IE11, emulation: IE9) "blocked content to help protect my privacy". By unblocking the content - click the sign next to the url - it worked like it should.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文