aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/document/location/index.html
blob: ebf1f2aa271d8bdeaf40e94d6984a7636ef12406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: Document.location
slug: Web/API/Document/location
translation_of: Web/API/Document/location
---
<p>{{APIRef("DOM")}}</p>

<p>A propriedade, de apenas leitura, <strong><code>Document.location</code></strong> retorna um objeto {{domxref("Location")}}, que contém informações sobre a URL do documento e provém métodos para mudar a URL e carregar outra URL.</p>

<p>Embora <code>Document.location</code> seja um objeto <code>Location de apenas leitura</code>,  você pode atribuir um {{domxref("DOMString")}} para ele. Isso significa que você pode trabalhar com document.location, na maioria dos casos, como se fosse uma string: <code>document.location = 'http://www.example.com'</code> é um sinônimo de <code>document.location.href = 'http://www.example.com'</code>.</p>

<p>Para recuperar somente a URL como uma string, a propriedade de apenas leitura {{domxref("document.URL")}} pode ser utilizada.</p>

<p>Se o documento atual não estiver no contexto de navegação, o valor retornado será <code>null</code>.</p>

<h2 id="Syntax" name="Syntax">Sintaxe</h2>

<pre class="syntaxbox"><em>locationObj</em> = document.location
document.location = 'http://www.mozilla.org' // Equivalente a document.location.href = 'http://www.mozilla.org'
</pre>

<h2 id="Example" name="Example">Exemplo</h2>

<pre class="brush: js">dump(document.location);
// Imprime uma string como
// "http://www.example.com/juicybits.html" to the console
</pre>

<h2 id="Especificações">Especificações</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Especificação</th>
   <th scope="col">Status</th>
   <th scope="col">Comentário</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "history.html#the-location-interface", "Document.location")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Nenhuma mudança de {{SpecName("HTML5 W3C")}}.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', "browsers.html#the-location-interface", "Document.location")}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>Definição inicial.</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidade_de_navegadores">Compatibilidade de navegadores</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Características</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Suporte básico</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Características</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Suporte básico</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="Veja_também">Veja também</h2>

<ul>
 <li>O valor da interface de retorno, {{domxref("Location")}}.</li>
 <li>Uma informação similar, mas anexada ao {{Glossary("browsing context")}}, {{domxref("Window.location")}}.</li>
</ul>

<p> </p>