StyleSheet.href

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.

hrefStyleSheet インターフェイスのプロパティで、スタイルシートの場所を返します。

文字列で、このスタイルシートの URI を保持します。

ローカルで下記のコードを実行してください。

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 sref() {
        alert(document.styleSheets[0].href);
      }
    </script>
  </head>
  <body>
    <div class="thunder">Thunder</div>
    <button onclick="sref()">ss</button>
  </body>
</html>

"file:////C:/Windows/Desktop/example.css" を返します。

メモ

スタイルシートがリンクされたスタイルシートの場合、この属性の値はその位置となります。 インラインスタイルシートの場合、この属性の値は NULL です。

このプロパティは Firefox、 Opera、 Google Chrome、 Safari では読み取り専用ですが、 Internet Explorer では読み取り / 書き込みともに可能となっています。

仕様書

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

ブラウザーの互換性

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