gdpr-consent
Version:
GDPR banner to comply with the European cookie law. Inspired by tarteaucitronjs.
23 lines (22 loc) • 680 B
JavaScript
export function addScript(url, attributes, callback) {
const script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = url;
for (const attrName in attributes) {
const attrVal = attributes[attrName];
if (attrVal !== undefined) {
script.setAttribute(attrName, attrVal);
}
}
if (typeof callback === "function") {
let done = false;
script.onload = function () {
if (done === false) {
done = true;
callback();
}
};
}
document.getElementsByTagName("head")[0].appendChild(script);
}