首页 文章

@ font-face - CSS字体的奇怪请求URL

提问于
浏览
0

这是一个愚蠢的问题,我假设有一个简单的解决方案 . 我在Wordpress主题中使用Web字体 - 我正在处理的网站有两个可用于访问同一网站的域 .

在我的CSS中,我使用font-squirrel格式来声明字体:

@font-face {
    font-family: 'Oswald';
    src: url('oswald-regular-webfont.eot');
    src: url('oswald-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('oswald-regular-webfont.woff') format('woff'),
         url('oswald-regular-webfont.ttf') format('truetype'),
         url('oswald-regular-webfont.svg#Oswald') format('svg');
    font-weight: normal;
    font-style: normal;
}

当我去其中一个域时,这工作正常,但当我通过其他域访问该网站时,该字体无法加载,因为它被认为是"cross-site"请求 . 基本上当我去domain1.com时,请求看起来像这样:http://www.domain1.com/fonts/oswald-regular-webfont.ttf

但是当我去domain2.com时,请求STILL看起来就像那样 . 为什么?自从我'm using relative paths, shouldn't domain2.com请求:http://www.domain2.com/fonts/oswald-regular-webfont.ttf

有谁知道我搞砸了什么? Wordpress是否以某种方式将完整路径注入CSS?

注意:它适用于Chrome,但不适用于Firefox或IE10 . Chrome具有相同的奇怪网址行为,不同之处仅在于Chrome允许跨网站请求 .

1 回答

  • 3

    这很可能发生,因为您正在使用 get_stylesheet_directory_uri() 或类似的方法来获取CSS文件的路径,然后在 wp_enqueue_style() 调用中使用它 .

    当这呈现给浏览器时,页面将具有文件的完整路径,而不是相对文件,这意味着字体文件相对于另一个站点,因此它是跨站点 .

相关问题