title: $.getScript gives Unexpected token
body: <p>I found some code online that helps me to provide widgets to my clients. My understanding of the full code below is that it first detects if jQuery is present otherwise loads it. As part of my widget I also want to ensure that fancybox is loaded because I am basically providing a button that onClicks loads an iframe in fancybox.</p>
  
  <p>The particular area of interest is in which <code>.getScript</code> gives me an error <code>Unexpected token .</code>. I know that <code>jQuery</code> is already loaded because <code>.getJSON</code> below works.</p>
  
  <p>Code:</p>
  
  <pre><code>    var fancyboxScript = widgetURL + "fancybox/source/jquery.fancybox.pack.js?v=2.1.5");
      $.getScript(fancyboxScript);
  
      /******* Load HTML *******/
      var jsonp_url = widgetURL + "widgetCall.php?callback=?";
      $.getJSON(jsonp_url,'merchantID='+merchantID, function(data) {
        $('#widget-container').html(data.html);
      });
  </code></pre>
  
  <p>The full code is below:</p>
  
  <pre><code>(function() {
  // Localize jQuery variable
  var jQuery;
  var widgetURL = "http://...mywidgetURL/...";
  /******** Load jQuery if not present *********/
  if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
    var script_tag = document.createElement('script');
    script_tag.setAttribute("type","text/javascript");
    script_tag.setAttribute("src",
      "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    if (script_tag.readyState) {
        script_tag.onreadystatechange = function () { // For old versions of IE
          if (this.readyState == 'complete' || this.readyState == 'loaded') {
            scriptLoadHandler();
          }
        };
    } else {
        script_tag.onload = scriptLoadHandler;
    }
  
    // Try to find the head, otherwise default to the documentElement
    (document.getElementsByTagName("head")[0] ||   document.documentElement).appendChild(script_tag);
  } else {
    // The jQuery version on the window is the one we want to use
    jQuery = window.jQuery;
    main();
  }
  
  /******** Called once jQuery has loaded ******/
  function scriptLoadHandler() {
    // Restore $ and window.jQuery to their previous values and store the
    // new jQuery in our local jQuery variable
    jQuery = window.jQuery.noConflict(true);
    // Call our main function
    main(); 
  }
  
  /******** Our main function ********/
  function main() {
    jQuery(document).ready(function($) { 
      /******* Load CSS *******/
      var css_link = $("&lt;link&gt;", { 
        rel: "stylesheet", 
        type: "text/css", 
        href: widgetURL + "myCSS.css" 
      });
      css_link.appendTo('head');
  
      /******* Load FANCYBOX *******/
      var fancy_link = $("&lt;link&gt;", { 
        rel: "stylesheet", 
        type: "text/css", 
        href: widgetURL + "fancybox/source/jquery.fancybox.css?v=2.1.5",
        media: "screen"
      });
      fancy_link.appendTo('head');
  
      var fancy2_link = $("&lt;link&gt;", { 
        rel: "stylesheet", 
        type: "text/css", 
        href: widgetURL + "fancybox/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7",
        media: "screen"
      });
      fancy2_link.appendTo('head');
  
      var fancyboxScript = widgetURL + "fancybox/source/jquery.fancybox.pack.js?v=2.1.5");
      $.getScript(fancyboxScript);
  
      /******* Load HTML *******/
      var jsonp_url = widgetURL + "widgetCall.php?callback=?";
      $.getJSON(jsonp_url,'merchantID='+merchantID, function(data) {
        $('#widget-container').html(data.html);
      });
    });
  }
  })(); // We call our anonymous function immediately
  </code></pre>