插入具有完整性和跨域属性问题的链接标记 [英] Inserting link tag with integrity and crossorigin attribute issue

查看:68
本文介绍了插入具有完整性和跨域属性问题的链接标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试用Java脚本插入CSS文档,但是我收到错误消息,要求必须启用CORS。有办法解决吗?

Trying to insert css document with Javascript, however I receive error saying that request has to be CORS enabled. Is there a way to deal with it?

这里是代码:

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://use.fontawesome.com/releases/v5.2.0/css/all.css';
link.integrity = 'sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ';
link.crossorigin = 'anonymous';
document.head.appendChild(link);


推荐答案

更改 crossorigin (不是有效的 HTMLLinkElement 属性)到 crossOrigin (注意大写的 O)。请记住,HTML元素属性通常在Javascript中使用驼峰拼写(第一个单词小写,所有后续单词的首字母大写)。

Change crossorigin (not a valid HTMLLinkElement attribute) to crossOrigin (note the capital "O"). Remember that HTML element properties are generally spelled in camel case (first word lower case with all subsequent words having their first letter capitalized) in Javascript.

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://use.fontawesome.com/releases/v5.2.0/css/all.css';
link.integrity = 'sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ';
link.crossOrigin = 'anonymous';
document.head.appendChild(link);

这篇关于插入具有完整性和跨域属性问题的链接标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆