Saturday, 1 February 2014

How can I get query string values in JavaScript?

You don't need jQuery for that purpose. You can use vanilla JavaScript:
function getParameterByName(name) {
name
= name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results
= regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More