URL.searchParams
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
A propriedade searchParams
da interface URL
retorna um objeto URLSearchParams
permitindo acesso ao GET
decodificando os argumentos que contém na URL.
Nota: This feature is available in Web Workers.
Valor
Um objeto URLSearchParams
.
Exemplos
Se a URl da sua página é
https://example.com/?name=Jonathan%20Smith&age=18
você pode analisar os parâmetros name
e age
utilizando:
js
let params = new URL(document.location).searchParams;
let name = params.get("name"); // é a string "Jonathan Smith".
let age = parseInt(params.get("age")); // é o número 18
Especificações
Specification |
---|
URL # dom-url-searchparams |
Compatibilidade de browser
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
searchParams |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.