url - How can I get query string values in JavaScript? -



url - How can I get query string values in JavaScript? -

is there plugin-less way of retrieving query string values via jquery (or without)?

if so, how? if not, there plugin can so?

you don't need jquery purpose. can utilize pure javascript:

function getparameterbyname(name, url) { if (!url) url = window.location.href; url = url.tolowercase(); // avoid case sensitiveness name = name.replace(/[\[\]]/g, "\\$&").tolowercase();// avoid case sensitiveness query parameter name var regex = new regexp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) homecoming null; if (!results[2]) homecoming ''; homecoming decodeuricomponent(results[2].replace(/\+/g, " ")); }

usage:

// query string: ?foo=lorem&bar=&baz var foo = getparameterbyname('foo'); // "lorem" var bar = getparameterbyname('bar'); // "" (present empty value) var baz = getparameterbyname('baz'); // "" (present no value) var qux = getparameterbyname('qux'); // null (absent)

note: if parameter nowadays several times (?foo=lorem&foo=ipsum), first value (lorem). there no standard , usages vary, see illustration question: authoritative position of duplicate http query keys.

javascript url plugins query-string

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -