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
That's a great use of the event delegation pattern.
1
+
C'est une bonne utilisation de la délégation d'évènement.
2
2
3
-
In real life instead of asking we can send a "logging" request to the server that saves the information about where the visitor left. Or we can load the content and show it right in the page (if allowable).
3
+
Dans la vie réelle au lieu de demander nous pouvons envoyer une requête de "logging" au serveur pour sauvegarder les informations sur où l'utilisateur a quitté. Ou nous pouvons charger le contenu et l'afficher directement dans la page (si permis).
4
4
5
-
All we need is to catch the `contents.onclick`and use`confirm`to ask the user. A good idea would be to use `link.getAttribute('href')`instead of`link.href`for the URL. See the solution for details.
5
+
Tout ce que nous avons à faire est de capturer le `contents.onclick`et utiliser`confirm`pour demander à l'utilisateur. Une bonne idée serait d'utiliser `link.getAttribute('href')`plutôt que`link.href`pour l'URL. Regardez la solution pour plus de détails.
Copy file name to clipboardExpand all lines: 2-ui/2-events/04-default-browser-action/2-catch-link-navigation/task.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,15 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Catch links in the element
5
+
# Capturer des liens dans l'élément
6
6
7
-
Make all links inside the element with `id="contents"`ask the user if they really want to leave. And if they don't then don't follow.
7
+
Faire en sorte que tous les liens dans l'élément avec `id="contents"`demande à l'utilisateur s'il veut vraiment partir. Et s'il ne veut pas ne suivez pas le lien.
8
8
9
-
Like this:
9
+
Commce ceci:
10
10
11
11
[iframe height=100 border=1 src="solution"]
12
12
13
-
Details:
13
+
Détails:
14
14
15
-
- HTML inside the element may be loaded or regenerated dynamically at any time, so we can't find all links and put handlers on them. Use event delegation.
16
-
-The content may have nested tags. Inside links too, like`<a href=".."><i>...</i></a>`.
15
+
-Le HTML à l'intérieur de l'élément peut être chargé ou regénéré dynamiquement à n'importe quel moment, donc nous ne pouvons pas trouver tous les liens et mettre des gestionnaires dessus. Utilisez la délégation d'évènement.
16
+
-Le contenu peut avoir des éléments imbriqués. À l'intérieur des liens aussi, comme ceci`<a href=".."><i>...</i></a>`.
The solution is to assign the handler to the container and track clicks. If a click is on the `<a>` link, then change`src`of`#largeImg`to the`href`of the thumbnail.
1
+
La solution est d'assigner le gestionnaire au conteneur et suivre les clics. Si un clic est sur le lien `<a>`, alors changer`src`de`#largeImg`pour le`href`de la miniature.
0 commit comments