diff options
Diffstat (limited to 'files/pt-br/web/api/url/searchparams/index.html')
-rw-r--r-- | files/pt-br/web/api/url/searchparams/index.html | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/files/pt-br/web/api/url/searchparams/index.html b/files/pt-br/web/api/url/searchparams/index.html new file mode 100644 index 0000000000..a711b85fa2 --- /dev/null +++ b/files/pt-br/web/api/url/searchparams/index.html @@ -0,0 +1,45 @@ +--- +title: URL.searchParams +slug: Web/API/URL/searchParams +translation_of: Web/API/URL/searchParams +--- +<p>{{APIRef("")}}</p> + +<p>A propriedade <strong><code>searchParams</code></strong> da interface {{domxref("URL")}} retorna um objeto {{domxref("URLSearchParams")}} permitindo acesso aos parâmetros enviados via GET que uma URL possui.</p> + +<h2 id="Sintaxe">Sintaxe</h2> + +<pre class="syntaxbox notranslate">var urlSearchParams = URL.searchParams;</pre> + +<h3 id="Valor">Valor</h3> + +<p>Um objeto {{domxref("URLSearchParams")}}.</p> + +<h2 id="Exemplo">Exemplo</h2> + +<p>Se a URL da sua página é <code>https://example.com/?name=Jonathan&age=18</code> você pode parsear os parametros 'name' e 'age' usando:</p> + +<pre class="default prettyprint prettyprinted notranslate">let params = (new URL(document.location)).searchParams; +let name = params.get("name"); // é a string "Jonathan" +let age = parseInt(params.get("age")); // é o número 18</pre> + +<h2 id="Especificações">Especificações</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('URL', '#dom-url-searchparams', 'searchParams')}}</td> + <td>{{Spec2('URL')}}</td> + <td>Definição inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{Compat("api.URL.searchParams")}}</p> |