Created
May 25, 2019 23:41
-
-
Save juliencrn/251b63a9f39098ecbe315afe40f00fa3 to your computer and use it in GitHub Desktop.
Read URL using JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming "?post=1234&action=edit" | |
const 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')); // "?post=1234&action=edit&active=1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment