【问题标题】:Google Chrome Application using Google Fonts使用 Google 字体的 Google Chrome 应用程序
【发布时间】:2014-12-11 05:54:59
【问题描述】:

我正在尝试包含链接样式表以使用 Google 字体中的字体。我已经尝试过 Web Font Loader 和实际的链接样式表,但我不断收到 CSP 错误。

Refused to load the stylesheet 'http://fonts.googleapis.com/css?family=Open+Sans:400,300,600'
because it violates the following Content Security Policy directive: 
"style-src 'self' data: chrome-extension-resource: 'unsafe-inline'".

这是我在manifest.json 中的 CSP

"content_security_policy": "default-src 'self'; style-src 'unsafe-inline'; script-src 'self';",

现在,由于我还没有阅读有关 CSP 的完整文档,因为当我尝试阅读此内容时,它似乎左右摇摆,也许有人可以告诉我这是如何工作的,我需要什么才能让我的样式表工作。

我尝试过的另一种方法:

 load({
    method:"GET",
    url:"http://fonts.googleapis.com/css?family=Open+Sans:400,300,600"
 },function(data){
   var style = document.createElement('style');
   var head = document.head;
   style.innerHTML = data.responseText;
   head.insertBefore(style, head.firstChild);
 });

【问题讨论】:

    标签: css fonts google-chrome-app


    【解决方案1】:

    出于安全原因,即使加载也不起作用,所以我做了更多研究,并在 Chrome 应用程序中使用 Google 字体使用导入方法而不是标准或 javascript。

    前:

    样式表

    @import url(http://fonts.googleapis.com/css?family=Open+Sans);
    body {
      font-family: 'Open Sans', sans-serif;
    }
    

    一切正常,就这样!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-25
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      相关资源
      最近更新 更多