Location: search

Esta tradução está incompleta. Ajude a traduzir este artigo em inglês

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

// Seleciona o elemento <a id="myAnchor" href="https://developer.mozilla.org/en-US/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ção

Especificação Status Comentário
HTML Living Standard
The definition of 'search' in that specification.
Padrão em tempo real Definição inicial.

Compatibilidade do navegador

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
searchChrome Full support YesEdge Full support 12Firefox Full support 22
Notes
Full support 22
Notes
Notes Before Firefox 53, the search property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, search would return "", rather than "?a=true&b=false".
IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 22
Notes
Full support 22
Notes
Notes Before Firefox 53, the search property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, search would return "", rather than "?a=true&b=false".
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
See implementation notes.
See implementation notes.