Skip to content

Instantly share code, notes, and snippets.

@robozavri
Created August 23, 2021 11:05
Show Gist options
  • Save robozavri/9b5c6e5910452c4e2d8790ad45b6fd09 to your computer and use it in GitHub Desktop.
Save robozavri/9b5c6e5910452c4e2d8790ad45b6fd09 to your computer and use it in GitHub Desktop.
[js get url params] #javascript #url #params
var urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.has('post')); // true
console.log(urlParams.get('action')); // "edit"
console.log(urlParams.getAll('action')); // ["edit"]
console.log(urlParams.toString()); // "?post=1234&action=edit"
console.log(urlParams.append('active', '1')); // "?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment