Skip to content

Commit 87315f4

Browse files
author
Vitor Talaia
committed
Adiciona o tópico HTML e JavaScript
1 parent ca7263f commit 87315f4

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

chapters/12-javascript-e-o-navegador.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,29 +184,50 @@ I will also usually omit the doctype. This is not to be taken as an encouragemen
184184
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.
185185

186186
## HTML and JavaScript
187+
## HTML e JavaScript
187188

188189
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.
189190

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+
```
192197

193198
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.
194199

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+
195202
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.
196203

197-
<h1>Testing alert</h1>
198-
<script src="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+
<script src="code/hello.js"></script>
209+
```
199210

200211
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.
201212

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+
202215
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.
203216

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+
204219
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.
205220

206-
<button onclick="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+
<button onclick="alert('Boom!');">DO NOT PRESS</button>
225+
```
207226

208227
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 `&quot;`, but that’d make the program harder to read.
209228

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 `&quot;`, mas isso tornaría o programa difícil de ler.
230+
210231
## In the sandbox
211232

212233
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

Comments
 (0)