StyleSheet: href-Eigenschaft

Baseline Widely available

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

Die href-Eigenschaft der StyleSheet-Schnittstelle gibt den Speicherort des Stylesheets zurück.

Diese Eigenschaft ist schreibgeschützt.

Wert

Ein String, der den URI des Stylesheets enthält.

Beispiele

Auf einem lokalen Windows-Rechner:

html
<!doctype html>
<html lang="en-US">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>href example</title>
    <link rel="styleSheet" href="example.css" />
    <script>
      function printRef() {
        alert(document.styleSheets[0].href);
      }
    </script>
  </head>
  <body>
    <div class="thunder">Thunder</div>
    <button onclick="printRef()">ss</button>
  </body>
</html>

Gibt "file:////C:/Windows/Desktop/example.css" zurück.

Hinweise

Wenn das Stylesheet ein verlinktes Stylesheet ist, ist der Wert seines Attributs dessen Speicherort. Für Inline-Stylesheets ist der Wert dieses Attributs null.

Spezifikationen

Specification
CSS Object Model (CSSOM)
# dom-stylesheet-href

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
href

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support