Here's a nice approach found in https://gist.github.com/jlong/2428561 to parse the URL:
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
Further can fetch the parameters from the search
like this:
// If I'm not mistaken, the search doesn't contain "?" prefix in all browsers
var search = parser.search.replace(/^\?/, '');
var params = search.split('&');
var map = {};
for (var i = 0; i < params.length; i++) {
var param = params[i].split('=');
map[param[0]] = param[1];
}
// map['id'] is what you need
Still it might be easier to use the javascript library "js-url", see https://github.com/websanova/js-url.
// will return "212"
url('?id', 'http://storecoupon.in/store/amazon-promo-codes/?id=212');