I\'m using the following to extract variables from a URL contained in a variable. It works fine in modern browsers but in IE8 it fails on the first variable but succeeds on
There have been some valid responses, but you may be interested in a function I use to retrieve GET parameters from URLs.
var get = function (name, url) { // Retrieves a specified HTTP GET parameter. Returns null if not found.
url = (typeof (url) === "undefined" ? window.location.href : url);
var regex = new RegExp("[?&]" + name + "=([^]*)");
var results = regex.exec(url);
var output = (results ? results[1] : null);
return output;
};
You could use it like this.
var url = 'http://sagensundesign.com?height=400&width=300';
var h = get("height",url);
var w = get("width",url);