aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/stylesheet/media/index.html
blob: 6c3de44d29d499019378bed2af67de57a074dc7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: StyleSheet.media
slug: Web/API/StyleSheet/media
tags:
  - API
  - CSSOM
  - Media
  - StyleSheet
  - プロパティ
translation_of: Web/API/StyleSheet/media
---
<div>{{APIRef("CSSOM")}}</div>

<p><strong>StyleSheet.media</strong> は、スタイル情報の対象として想定するメディアを指定します。これは読み取り専用で配列風の <code>MediaList</code> オブジェクトであり、 <code>deleteMedium()</code> で削除したり <code>appendMedium()</code> で追加したりすることができます。</p>

<h2 id="Example" name="Example"></h2>

<pre>&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;link rel="stylesheet" href="document.css" type="text/css" media="screen" /&gt;
&lt;style rel="stylesheet" type="text/css" media="screen, print"&gt;
body  { background-color: snow; }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;script&gt;
for (var iSheetIndex = 0; iSheetIndex &lt; document.styleSheets.length; iSheetIndex++)
 {
  console.log('document.styleSheets[' + String(iSheetIndex) + '].media: ' +
   JSON.stringify(document.styleSheets[iSheetIndex].media));
  if (iSheetIndex === 0)
    document.styleSheets[iSheetIndex].media.appendMedium('handheld');
  if (iSheetIndex === 1)
    document.styleSheets[iSheetIndex].media.deleteMedium('print');
  console.log('document.styleSheets[' + String(iSheetIndex) + '].media: ' +
   JSON.stringify(document.styleSheets[iSheetIndex].media));
 }
/*
will log:
document.styleSheets[0].media: {"0":"screen"}
document.styleSheets[0].media: {"0":"screen","1":"handheld"}
document.styleSheets[1].media: {"0":"screen","1":"print"}
document.styleSheets[1].media: {"0":"screen"}
*/
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>

<h2 id="Specification" name="Specification">仕様書</h2>

<p>DOM Level 2 Styles - STYLESHEET</p>

<p><a href="https://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html#StyleSheets-MediaList">W3C: Document Object Model Style Sheets - MediaList</a></p>