improve reload script to replicate all attributes
This commit is contained in:
parent
2435d610c7
commit
03f856025e
|
@ -57,22 +57,15 @@ function replaceScript(script) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var newScript = document.createElement("script");
|
var newScript = document.createElement("script");
|
||||||
|
|
||||||
newScript.async = false;
|
// replicate attributes and content
|
||||||
if (script.type !== "") {
|
for (let i = 0; i < script.attributes.length; i++) {
|
||||||
newScript.type = script.type;
|
newScript.setAttribute(script.attributes[i].name, script.attributes[i].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (script.src !== "") {
|
|
||||||
newScript.src = script.src;
|
|
||||||
if (script.integrity !== "") {
|
|
||||||
newScript.integrity = script.integrity;
|
|
||||||
}
|
|
||||||
if (script.crossorigin !== "") {
|
|
||||||
newScript.crossOrigin = script.crossOrigin;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newScript.innerHTML = script.innerHTML;
|
newScript.innerHTML = script.innerHTML;
|
||||||
}
|
|
||||||
|
// dynamically injected scripts cannot be async or deferred
|
||||||
|
newScript.async = false;
|
||||||
|
newScript.defer = false;
|
||||||
|
|
||||||
newScript.onload = () => resolve();
|
newScript.onload = () => resolve();
|
||||||
newScript.onerror = (error) => reject(error);
|
newScript.onerror = (error) => reject(error);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user