Skip to content

Commit 3494cdb

Browse files
modifiche
1 parent 67a15a5 commit 3494cdb

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

2-ui/2-events/04-default-browser-action/article.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
# Browser default actions
1+
# Azioni predefinite del browser
22

3-
Many events automatically lead to certain actions performed by the browser.
3+
Molti eventi vengono ricondotti verso determinate azioni eseguite dal browser.
44

5-
For instance:
5+
Per esempio:
66

7-
- A click on a link - initiates navigation to its URL.
8-
- A click on a form submit button - initiates its submission to the server.
9-
- Pressing a mouse button over a text and moving it - selects the text.
7+
- Un click su un link - inizializza la navigazione verso il suo URL.
8+
- Un click su un pulsante di invio di un form - inizializza l'invio dello stesso al server.
9+
- Premendo e spostando il pulsante su un testo - lo seleziona.
1010

11-
If we handle an event in JavaScript, we may not want the corresponding browser action to happen, and want to implement another behavior instead.
11+
Quando gestiamo un evento con JavaScript, potremmo non volere affatto che la corrispondente azione del browser avvenga, ed implementare, invece, un altro comportamento.
1212

13-
## Preventing browser actions
13+
## Prevenire le azioni del browser
1414

15-
There are two ways to tell the browser we don't want it to act:
15+
Ci sono due maniere per comunicare al browser che non vogliamo che esegua alcuna azione:
1616

17-
- The main way is to use the `event` object. There's a method `event.preventDefault()`.
18-
- If the handler is assigned using `on<event>` (not by `addEventListener`), then returning `false` also works the same.
17+
- La maniera principale è quella di usare l'oggetto `event`, all'interno del quale c'è il metodo `event.preventDefault()`.
18+
- Se il gestore viene assegnato tramite `on<event>` (e non tramite `addEventListener`), allora restiruire `false` avrà lo stesso effetto.
1919

20-
In this HTML a click on a link doesn't lead to navigation, browser doesn't do anything:
20+
In questo HTML un click su un link non porta a navigarlo, il browser di fatto non fa nulla:
2121

2222
```html autorun height=60 no-beautify
23-
<a href="/" onclick="return false">Click here</a>
24-
or
25-
<a href="/" onclick="event.preventDefault()">here</a>
23+
<a href="/" onclick="return false">Clicca qui</a>
24+
o
25+
<a href="/" onclick="event.preventDefault()">qui</a>
2626
```
2727

28-
In the next example we'll use this technique to create a JavaScript-powered menu.
28+
Nel prossimo esempio useremo questa tecnicaper creare un menù potenziato via JavaScript.
2929

30-
```warn header="Returning `false` from a handler is an exception"
31-
The value returned by an event handler is usually ignored.
30+
```warn header="Restituire `false` da un gestore è un'eccezione"
31+
Il valore restituito da un gestore evento solitamente viene ignorato.
3232

33-
The only exception is `return false` from a handler assigned using `on<event>`.
33+
L'unica eccezione è il `return false` di un gestore assegnato con l'uso di `on<event>`.
3434

35-
In all other cases, `return` value is ignored. In particular, there's no sense in returning `true`.
35+
In tutti gli altri casi, il valore del `return` viene ignorato. Nello specifico, non ha alcun senso restituire `true`.
3636
```
3737
38-
### Example: the menu
38+
### Esempio: il menù
3939
40-
Consider a site menu, like this:
40+
Considera un menù di questo tipo:
4141
4242
```html
4343
<ul id="menu" class="menu">
@@ -47,18 +47,18 @@ Consider a site menu, like this:
4747
</ul>
4848
```
4949

50-
Here's how it looks with some CSS:
50+
Ecco come appare con un po' di CSS:
5151

5252
[iframe height=70 src="menu" link edit]
5353

54-
Menu items are implemented as HTML-links `<a>`, not buttons `<button>`. There are several reasons to do so, for instance:
54+
Gli elementi del menù sono implementati com links HTML `<a>`, non pulsanti `<button>`. Ci sono tanti ragioni per fare ciò, per esempio:
5555

56-
- Many people like to use "right click" -- "open in a new window". If we use `<button>` or `<span>`, that doesn't work.
57-
- Search engines follow `<a href="...">` links while indexing.
56+
- A molte persone piace usare "tasto destro" -- "apri in una nuova finestra". Se usassimo `<button>` oppure `<span>`, questa funzionalità non potrebbe essere usata.
57+
- I motori di ricerca seguono i link `<a href="...">` per l'indicizzazione.
5858

59-
So we use `<a>` in the markup. But normally we intend to handle clicks in JavaScript. So we should prevent the default browser action.
59+
Quindi usiamo `<a>` nel markup. Ma normalmente intendiamo gestire i click tramite JavaScript e quidni dovremmo prevenire le azioni predefinite del browser.
6060

61-
Like here:
61+
Come in questo caso:
6262

6363
```js
6464
menu.onclick = function(event) {

0 commit comments

Comments
 (0)