user
In JavaScript, how to get url query ?s=id ?
alphonsio

To get the value of a query parameter (like ?s=id) in JavaScript, you can use the URLSearchParams API.

Here’s how to do it:

const params = new URLSearchParams(window.location.search);
const s = params.get('s');
console.log(s); // outputs "id" if the URL is like ?s=id

Example

If your page URL is https://example.com/page?s=5

Then params.get('s') will return 5.