remove appended script javascript

后端 未结 8 1638
执笔经年
执笔经年 2020-12-29 15:35

how can I remove my appended script because it causes some problems in my app.

This is my code to get my script

var nowDate = new Date().getTime();
v         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 16:09

    What you can do is remove the script immediately after it has been loaded:

    var nowDate = new Date().getTime();
    var url = val.redirect_uri + "notify.js?nocache=" + nowDate + "&callback=dummy";
    var script = document.createElement('script');
    script.src = url;
    script.onload = function( evt ) {
        document.body.removeChild ( this );
    }
    document.body.appendChild(script);
    

    Anyway I think it is a better idea to append the script to the header (where all the other scripts reside) than to the body.

提交回复
热议问题