10 examples of 'how to get query string value in jquery' in JavaScript

Every line of 'how to get query string value in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
82function getQueryStringValue(key) {
83 return decodeURIComponent(
84 window.location.search.replace(
85 new RegExp(
86 "^(?:.*[&\\?]" +
87 encodeURIComponent(key).replace(/[\.\+\*]/g, "\\$&") +
88 "(?:\\=([^&]*))?)?.*$",
89 "i"
90 ),
91 "$1"
92 )
93 );
94}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

12function getQueryVariable(variable) {
13 let query = window.location.search.substring(1);
14 let vars = query.split("&");
15 for (let i = 0; i < vars.length; i++) {
16 let pair = vars[i].split("=");
17 if (pair[0] == variable) { return pair[1]; }
18 }
19 return (false);
20}
230function updateQueryString (key, value) {
231 value = encodeURIComponent(value)
232
233 var url = window.location.href.replace(/([?&])(?:q|h)=([^&]+)(&|$)/, function (all, pre, value, end) {
234 if (end === '&') {
235 return pre
236 }
237 return ''
238 })
239 var re = new RegExp('([?&])' + key + '=.*?(&|#|$)(.*)', 'gi')
240 var hash
241
242 if (re.test(url)) {
243 if (typeof value !== 'undefined' && value !== null) { return url.replace(re, '$1' + key + '=' + value + '$2$3') } else {
244 hash = url.split('#')
245 url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '')
246 if (typeof hash[1] !== 'undefined' && hash[1] !== null) { url += '#' + hash[1] }
247 return url
248 }
249 } else {
250 if (typeof value !== 'undefined' && value !== null) {
251 var separator = url.indexOf('?') !== -1 ? '&' : '?'
252 hash = url.split('#')
253 url = hash[0] + separator + key + '=' + value
254 if (typeof hash[1] !== 'undefined' && hash[1] !== null) { url += '#' + hash[1] }
255 return url
256 } else { return url }
257 }
258}
58export function getQueryValue(name, url) {
59 if (!url) url = window.location.href;
60 name = name.replace(/[\[\]]/g, "\\$&");
61 const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
62 const results = regex.exec(url);
63 if (!results) return null;
64 if (!results[2]) return '';
65 return decodeURIComponent(results[2].replace(/\+/g, " "));
66}
61function getQsValue(){
62
63 //var resAgt = SrwOSGiApi.callOSGIService("com.sabre.edge.platform.core.sso.base.IAgentProfileService","getAgentId");
64
65
66 document.getElementById("whatsInQs").innerText = getParameterByName("qs");
67
68
69
70}
738public getQueryText(): string {
739 const filter = this.filters._query;
740 return filter instanceof Filter
741 ? filter.getValues()[0]
742 : "";
743}
118function getQuery(key){
119 var temp = location.search.match(new RegExp(key + "=(.*?)($|\&)", "i"));
120 if(!temp) return;
121 return temp[1];
122}
2function getQuery(querystring) {
3 var query = {};
4
5 var pairs = querystring.split('&'),
6 length = pairs.length,
7 keyval = [],
8 i = 0;
9
10 for (; i < length; i++) {
11 keyval = pairs[i].split('=', 2);
12 try {
13 keyval[0] = decodeURIComponent(keyval[0]); // key
14 keyval[1] = decodeURIComponent(keyval[1]); // value
15 } catch (e) {}
16
17 if (query[keyval[0]] === undefined) {
18 query[keyval[0]] = keyval[1];
19 } else {
20 query[keyval[0]] += ',' + keyval[1];
21 }
22 }
23
24 return query;
25}
500function getQueryString(field) {
501 var href = window.location.href;
502 var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
503 var string = reg.exec(href);
504 return string ? string[1] : null;
505}
90export function getQuery(url: string, name?: string) {
91 if (arguments.length < 2) {
92 name = url;
93 url = location.href
94 }
95 let match = /\?([^#]*)(#|$)/.exec(url);
96 if (match && (match = new RegExp("(^|&)" + encodeURIComponent(name).replace(/([\-.*+?^${}()|[\]\/\\])/g, '\\$1') + "=([^&]*)(&|$)", "i").exec(match[1]))) {
97 try {
98 match[2] = decodeURIComponent(match[2]);
99 } catch (e) { }
100 return match[2];
101 }
102}

Related snippets