[29] script
要素は、JavaScript のために使う以外に、
スクリプトから参照するなどの目的で任意の (文書の一部として直接レンダリングされるべきではない)
データを埋め込むことができます。これをデータブロックといいます。
[30] type
属性にデータの MIME型を指定します。
[13] <script type>
を参照。
[26] script
要素の内容に任意のテキストを含めることができます。
[27] ただし script
要素の終了タグとみなされる文字列は、
HTML構文では終了タグと解釈されてしまうので、含めることができません。
[28] なおHTML構文では script
要素の内容としてタグや注釈や文字参照は書けず、
そのままの文字データと解釈されます。
[31] 同じ Webページのスクリプトが処理に使うデータとして利用するのが想定された利用方法です。
[32] schema.org の JSON-LD データの埋め込みのように、 特定の利用者エージェントのみが利用するデータの埋め込みに流用されている場合もあります。
[6] スクリプトデータブロックとしての利用例がある MIME型は、
>>5 で「script_data_block
」フラグがついています。
[11] 次の MIME型には、埋め込みに関する明文規定があります。
application/its+xml
application/ld+json
application/csvm+json
application/ld+json;profile="http://www.w3.org/ns/anno.jsonld"
text/x-safeframe
[16] 次の MIME型には、埋め込みに関する曖昧な規定があります。
text/csv
.../...+csv
の独自の MIME型を使うべきもの)[39] その他用いられているもの:
[36] XML in HTML Meeting Report, , https://www.w3.org/TR/NOTE-xh#script-hack
[37] XML Data Islands, InetSDK, , https://web.archive.org/web/20001025170632/http://msdn.microsoft.com/xml/xmlguide/dataIslandhowto.asp
[33]
以前から稀にこうした使い方がなされていましたが、
HTML5 で正式な script
要素の用法の1つとなりました。
[35]
template
要素導入前は、
雛形記述にも使われていました。
現在はスクリプトデータブロックは雛形記述にはあまり使われなくなっています。
<!-- Parsely tracking params start --> <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "NewsArticle", "headline": "年賀状のサルを12年前と比べてみたら...デザイナーは同じ人、ヒツジでも話題に",
[10] Add <script type="module"> and module resolution/fetching/evaluation · whatwg/html@cd1a9fb ( 版) https://github.com/whatwg/html/commit/cd1a9fb1e83f7d0bc30be8b34ecdaf444a0b19a4
<!-- A map within your article -->
<figure class="op-map">
<script type="application/json" class="op-geotag">
{
"type": "Feature",
"geometry":
{
"type": "Point",
"coordinates": [ [23.166667, 89.216667], [23.166667, 89.216667] ]
},
"properties":
{
"title": "Jessore, Bangladesh",
"radius": 750000,
"pivot": true,
"style": "satellite",
}
}
</script>
</figure>
If the string starts with # it will be used as a querySelector and use the selected element’s innerHTML as the template string. This allows the use of the common <script type="x-template"> trick to include templates.
Another way to define templates is inside of a script element with the type text/x-template, then referencing the template by an id.
<script type="text/javascript+protovis">