How to catch url parameter of a script (while on client server) plugin in json
<p>So i have been able to catch in separate tests catching url parameters successfully. But i'm struggling with connecting it all up.</p>

<p>Where the parameter is in a second layer. If i can put the pubID in a var that would be great.</p>

<p>Or if somebody can point me in the right direction that would be great. Thanks</p>

<p>So i'm planning to build api widgets, but having trouble with getting parameter from the script</p>

<p>On the clients server i would have the following script</p>

<pre><code>&lt;script src="http://api.yoursite.com/js/loader.js?pubID=test123" type="text/javascript"&gt;&lt;/script&gt;
&lt;div id="myDiv"&gt;&lt;/div&gt;
</code></pre>

<p>Then the loader script would have the following code.</p>

<p>The following code is the loader.js file. This code has been written by someone else which works great for widgets, but having trouble to get the basics done haha</p>

<pre><code>(function() {

// Localize jQuery variable
var jQuery;

/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7.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.7.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: "style.css" 
    });
    css_link.appendTo('head'); 



    $.getJSON("http://api.yoursite.com/js/json.php?jsoncallback=?",
function(data){
  $('#myDiv').html(data.name);  
});

});
}

})(); // We call our anonymous function immediately
</code></pre>

<p>To catch the parameters i used the following working script.</p>

<pre><code>// Parse URL Queries
function url_query( query ) {
query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var expr = "[\\?&amp;]"+query+"=([^&amp;#]*)";
var regex = new RegExp( expr );
var results = regex.exec( window.location.href );
if( results !== null ) {
    return results[1];
    return decodeURIComponent(results[1].replace(/\+/g, " "));
} else {
    return false;
}
}

// Example usage - http://www.kevinleary.net/?load=yes
var url_param = url_query('pubID');
if( url_param ) {
alert(url_param); // "yes"
}
</code></pre>
