Skip to content Skip to sidebar Skip to footer

Inserting Link Tag With Integrity And Crossorigin Attribute Issue

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 = docu

Solution 1:

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);

Post a Comment for "Inserting Link Tag With Integrity And Crossorigin Attribute Issue"