字体被firefox阻止跨域请求被阻止:同源策略禁止在firefox处读取远程资源

时间:2019-08-08 19:45:48

标签: html css firefox cross-origin-read-blocking

当我在浏览器中打开html文件时,字体被firefox阻止,在其他浏览器上我没有任何问题,而这仅发生在mozila firefox上。

错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the 
remote resourceat file:///C:/Users/SajjaD/Desktop/PdfCar%20New%20Theme/Theme/PdfCar%20V2/fonts/WebY ekan.woff. (Reason: CORS request not http).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the 
remote resource at file:///C:/Users/SajjaD/Desktop/PdfCar%20New%20Theme/Theme/PdfCar%20V2/fonts/font awesome-webfont.woff2?v=4.5.0. (Reason: CORS request not http).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the 
remote resource at file:///C:/Users/SajjaD/Desktop/PdfCar%20New%20Theme/Theme/PdfCar%20V2/fonts/font awesome-webfont.woff?v=4.5.0. (Reason: CORS request not http).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the 
remote resource at file:///C:/Users/SajjaD/Desktop/PdfCar%20New%20Theme/Theme/PdfCar%20V2/fonts/fontawesome-webfont.ttf?v=4.5.0. (Reason: CORS request not http).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the 
remote resource at file:///C:/Users/SajjaD/Desktop/PdfCar%20New%20Theme/Theme/PdfCar%20V2/fonts/dinar.woff. (Reason: CORS request not http).

1 个答案:

答案 0 :(得分:1)

出现CORS错误的原因很可能是因为您是通过网络路径file:///C:/...而不是实际的HTTP请求来加载字体的。

disallows reading the remote resourceat file:

此消息从本质上讲意味着我们发现您要加载一些东西,但由于它是我们无权请求的网络驱动器上的本地文件资源,因此我们无法访问它。

您可能可以通过正确引用资源来绕过此错误,因此,与其指向file:///C://,不如从包含网站的根文件夹开始,然后从那里请求它们。 ../website/assets/fonts/font-file.ttf。但这是一个疯狂的猜测,因为我不知道您正在开发哪种技术堆栈。

您可以在此处了解更多信息:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp