jQuery- How to get the GET variable from a URL -
in js file, outputting hyperlinks based on data pulled api:
output += '<a class="reg_link" href="'+regobj.href+'?reg='+value+'" title="'+regobj.title+'" target="_blank">';
this works fine. however, later want find out ?reg=
value is.
$(".reg_link").each(function() { // how get variable url? });
i'm trying grab whatever value of variable is. how do that?
from how can query string values in javascript?
you don't need jquery purpose. can use pure javascript:
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, " ")); }
usage:
var reg = getparameterbyname('reg');
Comments
Post a Comment