evalScripts(text){
        let script
        , regexp = /<script(?:\s+src=('|")([\w.-/]+?)\1)?\s*>\s*([\s\S]*?)\s*<\/script>/gi
        , head = document.querySelectorAll('head')[0]
        , createScript = function(src,callback){
            let node = document.createElement('script');
            node.type = 'text/javascript';
            node.onload = node.onreadystatechange = function() {
                if(!/*@cc_on!@*/0 || this.readyState === 'loaded' || this.readyState === 'complete') {
                    this.onload = this.onreadystatechange = null; 
                    this.parentNode.removeChild(this);
                    typeof callback == 'function' && callback()
                }
            }
            node.src = src;
            return node;
        }
        ,serializeScript = function(){
            script = regexp.exec(text);
            if(!script){return}
            if(script[2]){
                let node = createScript(script[2],function(){
                    serializeScript(text)
                })
                head.appendChild(node)
            }else{
                window.execScript ? execScript(script[3]) : eval(script[3])
                serializeScript(text)
            }
        }
        serializeScript();
    }

 

相关文章:

  • 2018-05-04
  • 2022-12-23
  • 2021-07-20
  • 2021-07-23
  • 2021-10-18
  • 2021-07-06
  • 2021-09-25
猜你喜欢
  • 2021-11-03
  • 2021-12-03
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-07-04
相关资源
相似解决方案