Untitled

Mon Oct 18

jQuery getScript 関数を介して追加のスクリプトのデバッグ - efreedom

<code>&lt;script type=”text/javascript”&gt;

// Replace the normal jQuery getScript function with one that supports

// debugging and which references the script files as external resources

// rather than inline.

jQuery.extend({

   getScript: function(url, callback) {

      var head = document.getElementsByTagName(“head”)[0];

      var script = document.createElement(“script”);

      script.src = url;

      // Handle Script loading

      {

         var done = false;

         // Attach handlers for all browsers

         script.onload = script.onreadystatechange = function(){

            if ( !done &amp;&amp; (!this.readyState ||

                  this.readyState == “loaded” || this.readyState == “complete”) ) {

               done = true;

               if (callback)

                  callback();

               // Handle memory leak in IE

               script.onload = script.onreadystatechange = null;

            }

         };

      }

      head.appendChild(script);

      // We handle everything using the script element injection

      return undefined;

   },

});

&lt;/script&gt;

</code>