You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapters/12-javascript-e-o-navegador.md
+26-5Lines changed: 26 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -184,29 +184,50 @@ I will also usually omit the doctype. This is not to be taken as an encouragemen
184
184
Eu geralmente também irei omitir o *doctype*. Isso não deve ser interpretado como um incentivo a omitir declarações de *doctype*. Os navegadores frequentemente irão fazer coisas ridículas quando você esquece delas. Você deve considerá-las implicitamente presentes nos exemplos, mesmo quando elas não forem mostradas no texto.
185
185
186
186
## HTML and JavaScript
187
+
## HTML e JavaScript
187
188
188
189
In the context of this book, the most important HTML tag is `<script>`. This tag allows us to include a piece of JavaScript in a document.
189
190
190
-
<h1>Testing alert</h1>
191
-
<script>alert("hello!");</script>
191
+
No contexto desse livro, a *tag* mais importante do HTML é `<script>`. Essa *tag* nos permite incluir trechos de JavaScript em um documento.
192
+
193
+
```html
194
+
<h1>Testing alert</h1>
195
+
<script>alert("hello!");</script>
196
+
```
192
197
193
198
Such a script will run as soon as its `<script>` tag is encountered as the browser reads the HTML. The page shown earlier will pop up an alert dialog when opened.
194
199
200
+
Esse *script* será executado assim que a *tag*`<script>` for encontrada enquanto o navegador interpreta o HTML. A página mostrada acima irá exibir uma mensagem de alerta quando aberta.
201
+
195
202
Including large programs directly in HTML documents is often impractical. The `<script>` tag can be given an `src` attribute in order to fetch a script file (a text file containing a JavaScript program) from a URL.
196
203
197
-
<h1>Testing alert</h1>
198
-
<scriptsrc="code/hello.js"></script>
204
+
Incluir programas grandes diretamente no documento HTML é impraticável. A *tag*`<script>` pode receber um atributo `src` a fim de buscar um arquivo de *script* (um arquivo de texto contendo um programa em JavaScript) a partir de uma URL.
205
+
206
+
```html
207
+
<h1>Testing alert</h1>
208
+
<scriptsrc="code/hello.js"></script>
209
+
```
199
210
200
211
The `code/hello.js` file included here contains the same simple program, `alert("hello!")`. When an HTML page references other URLs as part of itself, for example an image file or a script, web browsers will retrieve them immediately and include them in the page.
201
212
213
+
O arquivo `code/hello.js` incluído aqui contém o mesmo simples programa, `alert("hello!")`. Quando uma página HTML referencia outras URLs como parte de si, por exemplo um arquivo de imagem ou um *script*, os navegadores irão buscá-los imediatamente e incluí-los na página.
214
+
202
215
A script tag must always be closed with `</script>`, even if it refers to a script file and doesn’t contain any code. If you forget this, the rest of the page will be interpreted as part of the script.
203
216
217
+
Uma *tag* de *script* deve sempre ser fechada com `</script>`, mesmo quando fizer referência para um arquvio externo e não contenha nenhum código. Se você esquecer disso, o restante da página será interpretado como parte de um *script* .
218
+
204
219
Some attributes can also contain a JavaScript program. The `<button>` tag shown next (which shows up as a button) has an `onclick` attribute, whose content will be run whenever the button is clicked.
205
220
206
-
<buttononclick="alert('Boom!');">DO NOT PRESS</button>
221
+
Alguns atributos podem conter um programa JavaScript. A *tag*`<button>` mostrada abaixo (que aparece como um botão na página) possui um atributo `onclick`, cujo conteúdo será executado sempre que o botão for clicado.
222
+
223
+
```html
224
+
<buttononclick="alert('Boom!');">DO NOT PRESS</button>
225
+
```
207
226
208
227
Note that I had to use single quotes for the string in the `onclick` attribute because double quotes are already used to quote the whole attribute. I could also have used `"`, but that’d make the program harder to read.
209
228
229
+
Perceba que eu tive que usar aspas simples para a *string* do atributo `onclick` porque aspas duplas já estão sendo usadas para envolver o valor do atributo. Eu também poderia ter usado `"`, mas isso tornaría o programa difícil de ler.
230
+
210
231
## In the sandbox
211
232
212
233
Running programs downloaded from the Internet is potentially dangerous. You do not know much about the people behind most sites you visit, and they do not necessarily mean well. Running programs by people who do not mean well is how you get your computer infected by viruses, your data stolen, and your accounts hacked.
0 commit comments