Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Javascript Obtain current url with query strings

//get the current url
const url = window.location.href;

//get the query string
const queryString = window.location.search;

//get the query string parameters
const params = new URLSearchParams(queryString);

//get the value of a specific parameter
const id = params.get('id');

console.log(url); //http://localhost:3000/index.html?id=1
console.log(queryString); //?id=1
console.log(params); //URLSearchParams { 'id' => '1' }
console.log(id); //1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)