TypeError:跨源请求仅受HTTP支持。仅在Safari 11中

时间:2018-07-10 07:58:15

标签: javascript typescript safari cors

 try {
     await this.GFontToDataURI('https://fonts.googleapis.com/css?family=' + label.fontfamily)
             .then(cssRules => {
                         style2.innerHTML += cssRules.join('\n');
                });
            }
  catch (ex) {
}

Safari 11抛出错误(其他浏览器未抛出):

TypeError: Cross origin requests are only supported for HTTP.

我使用此功能:How to use Google fonts in Canvas when Drawing DOM objects in SVG?

2 个答案:

答案 0 :(得分:-1)

http允许跨域,因此您可以将https更改为http。

或者如果您希望允许跨源请求https,则需要设置标题Access-Control-Allow-Origin

How do I use Access-Control-Allow-Origin? Does it just go in between the html head tags?

答案 1 :(得分:-1)

您能否尝试通过常规的fetch请求来获取字体? 我已经检查了野生动物园,一切似乎都工作正常。

fetch("https://fonts.googleapis.com/css?family=Helvetica")
  .then(res => console.log(res.text()))