Get URL Parameters with JavaScript

With the wide use of AJAX, sometimes we need get values of parameters from current URL, the below function is an very handy way to do so.

function getQuery(name)
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r =;
if (r!=null) return unescape(r[2]); return null;

Get the id’s value from


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>