动态加载js

function load_js(src) {
            var xml_http = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
            xml_http.onreadystatechange = function() {
                if (xml_http.readyState == 4) {
                    var script_element = document.createElement('script');
                    document.getElementsByTagName('head')[0].appendChild(script_element);
                    script_element.text = xml_http.responseText;
                }
            }
            xml_http.open('GET', src, true);
            xml_http.send('');
}

调用方法:

 if (! +[1, ]) {

load_js("js/excanvas.js");//如果是ie浏览器就加载js
}

http://www.perfgeeks.com/?p=543

原文地址:https://www.cnblogs.com/wangjunwei/p/2776544.html