Friday, September 28, 2012

Function for accessing URL variables in HTML

Function for accessing URL variables in HTML:

function getUrlVar(key){
        var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
         return result && unescape(result[1]) || "";
}

Ex:
URL: http://blog.com?name=suresh&lastname=raja
you have to use the function like this getUrlVal('name') you will get the result as 'suresh'.