function gup(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
The way that the function is used is fairly simple. Let's say you have the following URL:
http://localhost/script/directory/NAMES.ASP?name=Fred&id=123
You want to get the value from the frank parameter so you call the javascript function as follows:
var name_param = gup( 'name' );
No comments:
Post a Comment