Location: search
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 search
da interface Location
é um texto de busca, também chamado de query string ou querystring; isso é, uma USVString
contendo um '?'
seguido pelos parâmetros da URL.
Os navegadores modernos fornecem o URLSearchParams
e o URL.searchParams
para facilitar a análise dos parâmetros da querystring.
Sintaxe
string = object.search; object.search = string;
Exemplos
js
// Seleciona o elemento <a id="myAnchor" href="https://developer.mozilla.org/pt-BR/docs/Location.search?q=123">
var anchor = document.getElementById("myAnchor");
var queryString = anchor.search; // Retorna:'?q=123'
// Análise adicional:
let params = new URLSearchParams(queryString);
let q = parseInt(params.get("q")); // é o número 123
Especificações
Specification |
---|
HTML # dom-location-search-dev |
Compatibilidade com navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
search |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
- User must explicitly enable this feature.
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.