XMLHttpRequest脚本注入

function loadScript(url){
    let xhr = new XMLHttpRequest()
    xhr.open('get',url,true)
    xhr.onreadystatechange = function(){
        if(xhr.readyState == 4){
            if(xhr.status >= 200 && xhr.status <= 300 || xhr.status == 304){
                let script  = document.createElement('script')
                script.type = 'text/javascript'
                script.text = xhr.responseText
                document.body.appendChild(script)
            }
        }
    }
    xhr.send(null)
}
posted @ 2020-09-19 13:50  671_MrSix  阅读(300)  评论(0编辑  收藏  举报