日期:2014-05-16  浏览次数:20365 次

動態載入js

<script type="text/javascript">
  var loadJS = function (params) {
    var head = document.getElementsByTagName("head")[0];

    var script = document.createElement('script');

    script.onload = script.onreadystatechange = script.onerror = function () {
      if (script && script.readyState && /^(?!(?:loaded|complete)$)/.test(script.readyState)) return;

      script.onload = script.onreadystatechange = script.onerror = null;
      script.src = '';
      script.parentNode.removeChild(script);
      script = null;

      if (typeof params.callback == "function")
        params.callback();
    };
    script.charset = params.charset || document.charset || document.characterSet || 'utf-8';
    script.src = params.src;

    try {
      head.appendChild(script);
    } catch (exp) {
    }
  };
  (function(oWin) {
    if ((!oWin.parent && !oWin.dialogArguments) ||(oWin.parent && !oWin.parent.dialogArguments) ) {
      loadJS({src: "../../js/cookie.js", charset:"utf-8"});
    }
  })(window);
</script>