How to pass a parameter to a javascript through a url and display it on a page?

Shouldn't be too difficult to write your own without the need for an external library.

// www.mysite.com/my_app.html?Use_Id=abc 

var GET = {};
var query = window.location.search.substring(1).split("&");
for (var i = 0, max = query.length; i < max; i++)
{
    if (query[i] === "") // check for trailing & with no param
        continue;

    var param = query[i].split("=");
    GET[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || "");
}

Usage: GET.Use_id or GET["Use_id"]. You can also check if a parameter is present even if it has a null value using "Use_id" in GET (will return true or false).


Call the page www.mysite.com/my_app.html?Use_Id=abc

Then in that page use a javascript function like:

var urlParam = function(name, w){
    w = w || window;
    var rx = new RegExp('[\&|\?]'+name+'=([^\&\#]+)'),
        val = w.location.search.match(rx);
    return !val ? '':val[1];
}

To use it:

var useId = urlParam('Use_Id');

The second parameter w is optional, but useful if you want to read parameters on iframes or parent windows.