Jquery plugin to read query string - how to

If you are looking for some jQuery plugin to read the query string parameters then you are on right page. Here is a simple function which will help you to understand how to detect/read the values of query string parameters.

Jquery Plugin

$.queryParam = function(name){

var answer = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);

if (!answer)
{
return 0;
}
return answer[1] || 0;
}


How to use
var paramValue = $.queryParam('paramName');

0 comments:

Post a Comment

Share this post with your friends