admin管理员组文章数量:1404569
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?
Here is the code:
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = '.2.0/css/all.css';
link.integrity = 'sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ';
link.crossorigin = 'anonymous';
document.head.appendChild(link);
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?
Here is the code:
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://use.fontawesome./releases/v5.2.0/css/all.css';
link.integrity = 'sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ';
link.crossorigin = 'anonymous';
document.head.appendChild(link);
Share
Improve this question
edited Dec 12, 2018 at 0:16
Unmitigated
89.8k12 gold badges99 silver badges104 bronze badges
asked Aug 20, 2018 at 21:17
kkris1983kkris1983
4932 gold badges7 silver badges18 bronze badges
1 Answer
Reset to default 7Change 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./releases/v5.2.0/css/all.css';
link.integrity = 'sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ';
link.crossOrigin = 'anonymous';
document.head.appendChild(link);
本文标签: javascriptInserting link tag with integrity and crossorigin attribute issueStack Overflow
版权声明:本文标题:javascript - Inserting link tag with integrity and crossorigin attribute issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744832017a2627407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论