Home

Published

- 1 min read

jquery get query params

img of jquery get query params

The solution for this is noted below

jquery get query params

Solution

   //Assuming URL is "https://example.com/test/?post=1234&action=edit"
var base_url = window.location.origin //https://example.com
var host = window.location.host //example.com
var pathArray = window.location.pathname.split('/') //returns object ['', 'test', '']
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')) // "?

Try other methods by searching on the site. That is if this doesn’t work