title: Dynamic loading of jwplayer or any js file
body: <p>I want to load jwplayer dynamically using jquery or javascript. I want to do this because the browser on which FLASH is not installed jwplayer in not behaving as expected.</p>
  
  <p>Hence I want to check first whether flash player is installed or not into the browser if yes than only I want to load jwplayer.To check flash installed or not i m using below</p>
  
  <pre><code>var hashFlash=((typeof navigator.plugins != "undefined" &amp;&amp; typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject &amp;&amp; (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false));
  </code></pre>
  
  <p>if hashFlash is true than only i will load jwplayer to play video/audio.</p>
  
  <p>I am using below code to load jwplayer dynamically.</p>
  
  <pre><code>function loadjwplayer(filename) {
      var fileref=document.createElement('script');
      fileref.setAttribute("type","text/javascript");
      fileref.setAttribute("src", filename);
      alert(fileref);
      document.getElementsByTagName("head")[0].appendChild(fileref);
  }
  </code></pre>
  
  <p>OR through jquery as below</p>
  
  <pre><code>$.getScript("/jwplayer/jwplayer.js");
  </code></pre>
  
  <p>After that i will add audio/video player into the we page as per requirement using below.</p>
  
  <pre><code>function load_jwplayer_skin( div_id, audio_file) { 
      jwplayer(div_id).setup({
                        file: audio_file,
                        flashplayer: "/jwplayer/jwplayer.flash.swf",    
                        primary: "flash",
                        width: "350", 
                        height: "25", 
                      });
  }
  </code></pre>
  
  <p>and use it into html as below</p>
  
  <pre><code>&lt;div id='audio_1'&gt;......&lt;/div&gt;
  &lt;script&gt;
  load_jwplayer_skin('audio_1','my_fev_song.mp3');
  &lt;/script&gt;
  </code></pre>
  
  <p>But I am getting below error "Uncaught Referenceerror: Jwplayer is not defined inside function load_jwplayer_skin ".</p>
  
  <p>The same is working fine if I load jwplayer using ..... at head of the page.Hence it seems me that jwplayer is not available in global scope. </p>
  
  <p>Please someone suggest me how to proceed.</p>