Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

Is there a plugin-less way of retrieving query string values via jQuery (or without)?

If so, how? If not, is there a plugin which can do so?

1 Answer

0 votes
by (106k points)
edited by

To getting the query string values in JavaScript you can use URLSearchParams which is simple and has good browser support. You can use the below-mentioned code:-

const urlParams = new URLSearchParams(window.location.search); 

const myParam = urlParams.get('myParam');

You can directly use the JavaScript there is no need of JQuery see the below-mentioned code:-

function getParameterByName(name, url) {

if (!url) url = window.location.href; 

name = name.replace(/[\[\]]/g, '\\$&'); 

var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(url); 

if (!results) return null; 

if (!results[2]) return ''; 

return decodeURIComponent(results[2].replace(/\+/g, ' ')); 

}

Enroll in our web development course to become as an Expert in Web Development! 

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 10, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
asked Aug 13, 2019 in Web Technology by Sammy (47.6k points)
+1 vote
1 answer

Browse Categories

...