You need to parse an URL and return all the parameters from the URL, you can use the below javascript function:-
var getURLParameters = function(url) {
var result = {};
var searchIndex = url.indexOf("?");
if (searchIndex == -1 ) return result;
var sPageURL = url.substring(searchIndex +1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
result[sParameterName[0]] = sParameterName[1];
}
return result;
};
Usage:
var url = 'http://www.example.com/?id=1&user=username&password=password;
var params = getURLParameters(url);
console.log(params);
Result:
Object {id: 1, user: "username", password: "password"}
0 Comment(s)