Monday, December 10, 2012

How to get query string value using javascript

String.prototype.GetQSValue = function() {
    if (!arguments[0]) return null;
    var strFL = unescape(this)
    var regEx = new RegExp("[?&]" + arguments[0] + "=.*$", "g");
    var strMatch = strFL.match(regEx);
    if (strMatch == null) return null
    var arrParts = strMatch.toString().split("&");
    return (arrParts[0].length == 0) ? arrParts[1].split("=")[1] : arrParts[0].split("=")[1];
}
How to call this function, you can see this in bottom. I am getting here "return" parameter's value.
var strLink = window.location.search;
var returnurl = strLink.GetQSValue('return');

No comments:

Post a Comment