From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/string/anchor/index.html | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/string/anchor/index.html (limited to 'files/fr/web/javascript/reference/global_objects/string/anchor') diff --git a/files/fr/web/javascript/reference/global_objects/string/anchor/index.html b/files/fr/web/javascript/reference/global_objects/string/anchor/index.html new file mode 100644 index 0000000000..b5f3fb1ea1 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/string/anchor/index.html @@ -0,0 +1,86 @@ +--- +title: String.prototype.anchor() +slug: Web/JavaScript/Reference/Objets_globaux/String/anchor +tags: + - JavaScript + - Méthode + - Prototype + - Reference + - String + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/String/anchor +--- +
{{JSRef}}
+ +

La méthode anchor() permet de créer une ancre HTML {{HTMLElement("a")}} qui est utilisé comme cible hypertexte.

+ +

Syntaxe

+ +
str.anchor(name)
+ +

Paramètres

+ +
+
name
+
Une chaîne de caractères représentant l'attribut name de la balise à créér.
+
+ +

Valeur de retour

+ +

Une chaîne de caractères qui représente un élément HTML {{HTMLElement("a")}}.

+ +

Description

+ +

On utilise la méthode anchor() pour créer et afficher des ancres dans un document HTML à l'aide de JavaScript.

+ +

Ici la chaîne représente le texte que verra l'utilisateur. Le paramètre name représente l'attribut name de l'élément {{HTMLElement("a")}}.

+ +

Les ancres créées avec la méthode anchor deviennent des éléments accessibles à travers le tableau {{domxref("document.anchors")}}.

+ +

Exemples

+ +
var maChaîne = "Table des matières";
+
+document.body.innerHTML = maChaîne.anchor("ancre_contenu");
+ +

produira le code HTML suivant :

+ +
<a name="ancre_contenu">Table des matières</a>
+ +

Prothèse d'émulation (polyfill)

+ +
if (!String.prototype.anchor){
+  String.prototype.anchor = function(x){
+    return '<a name="' + x + '">' + this + '</a>'
+  };
+}
+
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES6', '#sec-string.prototype.anchor', 'String.prototype.anchor')}}{{Spec2('ES6')}}Définition initiale. Implémentée avec JavaScript 1.0. Défini dans l'annexe (normative) B sur les fonctionnalités additionnelles des navigateurs web.
+ +

Compatibilité des navigateurs

+ + + +

{{Compat("javascript.builtins.String.anchor")}}

+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf