Your jquery could be
$(function() {
$('.popuptest a').live('click', function(event) {
$.extend({ getUrlVars: function(){
var vars = [], hash;
var hashes = $('.popuptest a').attr("href").slice($('.popuptest a').attr("href").indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function(name){
return $.getUrlVars()[name];
}
});
var second = $.getUrlVars()["param2"];
alert(second);
return false;
});
});
things to note:
it's so easy, all you have to do is put the variable name that you want it from the URL into this function then it will return you the value of URL variable
function getParameterByName(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
small improvement, parse the url only once, return array or params:
function getURLParameters(url){
var result = {};
var hashIndex = url.indexOf("#");
if (hashIndex > 0)
url = url.substr(0, hashIndex);
var searchIndex = url.indexOf("?");
if (searchIndex == -1 ) return result;
var sPageURL = url.substring(searchIndex +1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
result[sParameterName[0]] = sParameterName[1];
}
return result;
}
http://jsfiddle.net/shakhal/gXM3u/
You don't need jQuery for that purpose you can use the pure JavaScript:
function getParameterByName( name,href )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( href );
if( results == null )
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
and you can call the function in this way..getParameterByName(param1,href of your link)
DEMO
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
So simple you can use any url and get value in Javascript.And this is Complete set of codes
<!DOCTYPE html>
<html>
<head>
<script>
var tech = getQueryVariable('filename');
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
alert(tech);
</script>
</head>
<body>
<p>Get parameters of a url</p>
</body>
</html>