var oScript = document.createElement('script');
    oScript.type = 'text/javascript';
    oScript.src = "xx.js";
    /*
    ** script标签的onload和onreadystatechange事件
    ** IE6/7/8支持onreadystatechange事件
    ** IE9/10支持onreadystatechange和onload事件
    ** Firefox/Chrome/Opera支持onload事件
    */

    // 判断IE8及以下浏览器
    var isIE = !-[1, ];
    if (isIE) {
        oScript.onreadystatechange = function () {
//ie 即使404readyState也是loaded或complete
if (this.readyState == 'loaded' || this.readyState == 'complete') { callback(); } } } else { // IE9及以上浏览器,Firefox,Chrome,Opera oScript.onload = function () { callback(); }
      oScript.onerror = function () {
          //error callback
        }
} 
var head = document.getElementsByTagName('head')[0];
head.appendChild(oScript);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2021-07-24
  • 2022-03-07
  • 2021-12-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2022-01-07
  • 2021-10-14
  • 2022-12-23
  • 2021-06-14
相关资源
相似解决方案