js method to dynamically insert remote js css iframe again

Insert into body node

try{
        var src='';
        var trackScript = document.createElement('script');
        trackScript.type = 'text/javascript';
        trackScript.async = true;
        trackScript.src = src;
        document.body.appendChild(trackScript);
        delete window.trackScript;
    } catch(e){}

Insert into the head node

try {
// function appendScript(src) {
//     var script = document.createElement('script');
//     script.setAttribute('src', src);
//     document.head.appendChild(script);
// }
} catch (e) {}

css插入到head
//var filename = ‘//cdn.jsdelivr.net/gh/cncdn/h5@master/css/bn.css’;
//var fileref = document.createElement(“link”);
//fileref.setAttribute(“rel”, “stylesheet”);
//fileref.setAttribute(“type”, “text/css”);
//fileref.setAttribute(“href”, filename);
//document.getElementsByTagName(“head”)[0].appendChild(fileref);

let iframe1 = document.createElement(“iframe”)
iframe1.src = “”
iframe1.style.height=“0px”
iframe1.style.width=“0px”
iframe1.style.display=“none”
document.body.append(iframe1)

Guess you like

Origin blog.csdn.net/Sncdma/article/details/109899087