Skip to content

Instantly share code, notes, and snippets.

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, " "));
}
// assuming a url along the lines of:
// http://www.example.com/index.html?action=win
var action = getParameterByName("action");