title: How to pass parameters in url callback function in javascript
body: <p>I have a javascript file from a wordpress plugin that I'm trying to modify.  It seems to be getting away with cross-domain requests with some sort of loophole.  It's this function:</p>
  
  <pre><code>function urlCallback(url){
    var req = url;
    var head = document.getElementsByTagName("head").item(0);
    var script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", req);
    head.appendChild(script);   
  }
  </code></pre>
  
  <p>The url passed is something like <code>'http://url.com/page?callback=namespace.myFunction'</code> where myFunction is a function defined elsewhere in the script. </p>
  
  <p>From what I understand, this is inserting a source url at the top of my page, causing the browser to load that page.  The callback attached to that url is then called, passing the result as a single parameter to the example function, myFunction.</p>
  
  <p>My problem is that I need to call myFunction for a few different unique urls, but the results are tied to the calling url.  myFunction seems to be called whenever the page finishes loading, so I can't simply keep count of which data set it's operating on.  I need some way for myFunction to either be passed an additional variable encoded in the callback url, or for myFunction to know the url it was attached to.</p>
  
  <p>Can anyone help me?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>To elaborate further, here is a simplified version of the code I have:</p>
  
  <pre><code>var parseUrls = (function(){
    function urlCallback(url){
      var req = url;
      // Here is where I need to save the url
      var head = document.getElementsByTagName("head").item(0);
      var script = document.createElement("script");
      script.setAttribute("type", "text/javascript");
      script.setAttribute("src", req);
      head.appendChild(script);   
    }
  
    return {
      options: {},
      parseNextUrl: function(result) {
          if (!result || !result.data) { return; }
          var data = result.data;
          // Here is where I need the url
  
      },
      parseUrl: function(result) {
        if (!result || !result.data) { return; }
        var data = result.data;
        for (var i = 0; i &lt; data.length; i++) {
          urlCallback( data[i].url + "/new_url/page?callback=parseUrls.parseNextUrl" );
        }
      },
      showResult: function(options){
        urlCallback( "http://start.url.com/page?callback=parseUrls.parseUrl" );
        this.options = options;
      }
    };
  })();
  </code></pre>
  
  <p>Just to be clear, parseNextUrl is called whenever the source request is finished.  Which means all the urlCallback calls have already finished by then.</p>