HTMLLinkElement: hreflang-Eigenschaft

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Die hreflang-Eigenschaft des HTMLLinkElement-Interfaces wird verwendet, um die Sprache und die geografische Ausrichtung einer Seite anzugeben. Dieser Hinweis kann von Browsern genutzt werden, um die passendere Seite auszuwählen oder um das SEO zu verbessern.

Sie spiegelt das hreflang-Attribut des <link>-Elements wider und ist der leere String (""), wenn kein hreflang-Attribut vorhanden ist.

Wert

Ein String, der ein Sprach-Tag enthält, oder der leere String (""), wenn kein hreflang-Attribut vorhanden ist.

Beispiel

html
<link
  rel="alternate"
  href="www.example.com/fr/html"
  hreflang="fr"
  type="text/html"
  title="French HTML" />
<p class="tag"></p>
css
.tag {
  margin-left: 20px;
  font: bold;
  font-size: 24px;
}
js
const myLink = document.querySelector("link");
const pTag = document.querySelector(".tag");
pTag.textContent = myLink.hreflang;

Ergebnisse

Spezifikationen

Specification
HTML
# dom-link-hreflang

Browser-Kompatibilität

Siehe auch