Skip to content

reference js queryString

ax1 edited this page Feb 23, 2024 · 2 revisions

queryString()

Get the URL queryString, or the value or a parameter.

Typically the queryString can be retrieved by using window.location.search but it the url is hashed (#/...) the search contains also the hash part. This function allows to focus on the queryString itself either retrieving it or extracting a parameter value.

queryString([key])

key: {String} [optional] the parameter key to look for

return: {String} If no key, return the full queryString. If key, return the param value, if key not found return "".

Examples:

// url = 'http://.../#/.../?app31'
const qs = ir.queryString() // qs === app31

// url = 'http://.../#/.../?id=11&filter=true'
const  id = ir.queryString('id') // id === 11
const  name = ir.queryString('name') // name === ''

Clone this wiki locally