Living Standard â Last Updated 1 September 2026
ã¹ã¯ãªããã¯èè ãææžã«åæ¹åæ§ã远å ããããšãèš±å¯ããã
èè ã¯ã宣èšåã®ã¡ã«ããºã ããã°ãã°ããä¿å®ããããããã€å€ãã®ãŠãŒã¶ãŒãã¹ã¯ãªãããç¡å¹ãšããŠãããããå¯èœã§ããã°ãã¹ã¯ãªããã«å®£èšåã®ä»£æ¿ã䜿çšããããæšå¥šãããã
ããšãã°ãããè©³çŽ°ãªæ
å ±ã衚瀺ããã»ã¯ã·ã§ã³ã衚瀺ãŸãã¯é衚瀺ã«ããã¹ã¯ãªããã䜿çšãã代ããã«ãdetailsèŠçŽ ã䜿çšã§ããã
èè ã¯ãŸããã¹ã¯ãªããã®ãµããŒãããªãç¶æ ã§ãããã®ã¢ããªã±ãŒã·ã§ã³ãè¡åãããã°ã¬ãŒãããããæšå¥šãããã
ããšãã°ãèè ãããŒãã«ããããŒã«ãããŠãªã³ã¯ã«åçãªããŒãã«ã®åãœãŒããæäŸããå Žåããªã³ã¯ã¯ãŸããµãŒããŒãããœãŒããããããŒãã«ãèŠæ±ããããšã«ãã£ãŠãã¹ã¯ãªãããªãã§æ©èœãããããšãã§ãããããããªãã
scriptèŠçŽ Support in all current engines.
Support in all current engines.
src屿§ãååšããªãå Žåãtype屿§ã®å€ã«äŸåããããã¹ã¯ãªããã®å
容å¶éã«äžèŽããªããã°ãªããªããsrc屿§ãååšããå ŽåãèŠçŽ ã¯ç©ºãŸãã¯ã¹ã¯ãªããææžãå«ãã ãã§ãªãã¹ã¯ãªããã®å
容å¶éã«äžèŽãããã®ããããã§ãªããã°ãªããªããtype â ã¹ã¯ãªããã®çš®é¡src â ãªãœãŒã¹ã®ã¢ãã¬ã¹nomodule â ã¢ãžã¥ãŒã«ã¹ã¯ãªããããµããŒããããŠãŒã¶ãŒãšãŒãžã§ã³ãã«ãããå®è¡ãé²ãasync â ãã§ããã®éãããã¯ãªãã§ãå¯èœãªå Žåã«ã¹ã¯ãªãããå®è¡ããdefer â ã¹ã¯ãªããã®å®è¡ãå»¶æããblocking â èŠçŽ ãæœåšçã«ã¬ã³ããªã³ã°ããããã³ã°ã§ãããã©ãã crossorigin â èŠçŽ ãçæå
ããŸããã èŠæ±ãåŠçããæ¹æ³referrerpolicy â èŠçŽ ã«ãã£ãŠéå§ããããã§ããã®ããã®ãªãã¡ã©ãŒããªã·ãŒintegrity â Subresource Integrityãã§ãã¯ã§äœ¿çšãããæŽåæ§ã¡ã¿ããŒã¿[SRI]fetchpriority â èŠçŽ ã«ãã£ãŠéå§ããããã§ããã®åªå
床ãèšå®ãã[Exposed =Window ]
interface HTMLScriptElement : HTMLElement {
[HTMLConstructor ] constructor ();
[CEReactions , Reflect ] attribute DOMString type ;
[CEReactions , ReflectURL ] attribute USVString src ;
[CEReactions , Reflect ] attribute boolean noModule ;
[CEReactions ] attribute boolean async ;
[CEReactions , Reflect ] attribute boolean defer ;
[SameObject , PutForwards =value , Reflect ] readonly attribute DOMTokenList blocking ;
[CEReactions ] attribute DOMString ? crossOrigin ;
[CEReactions ] attribute DOMString referrerPolicy ;
[CEReactions , Reflect ] attribute DOMString integrity ;
[CEReactions ] attribute DOMString fetchPriority ;
[CEReactions ] attribute DOMString text ;
static boolean supports (DOMString type );
// also has obsolete members
};
scriptèŠçŽ ã¯ãèè
ãææžã«åçã¹ã¯ãªããããŠãŒã¶ãŒãšãŒãžã§ã³ããžã®åœä»€ãããã³ããŒã¿ãããã¯ãå«ããããšãå¯èœã«ããããã®èŠçŽ ã¯ããŠãŒã¶ãŒã«ã³ã³ãã³ãã衚ããã®ã§ãªãã
Support in all current engines.
scriptèŠçŽ ã«ã¯ã2ã€ã®ã³ã¢å±æ§ããããtype屿§ã¯ã衚ãããã¹ã¯ãªããã®åã®ã«ã¹ã¿ãã€ãºãå¯èœã«ããïŒ
屿§ãçç¥ããã空æååã«èšå®ããããŸãã¯JavaScript MIMEã¿ã€ããšãã»ã³ã¹ãããã«èšå®ããããšã¯ããã®ã¹ã¯ãªãããã¯ã©ã·ãã¯ã¹ã¯ãªããã§ãããJavaScript Scriptãããã¬ãã«å¶äœç©ã«ãã£ãŠè§£éãããããšãæå³ãããèè
ã¯type屿§ãéè€ããŠèšå®ããã®ã§ã¯ãªããçç¥ãã¹ãã§ããã
"module"ã«ASCII倧æåã»å°æåäžåºå¥ã§äžèŽãã屿§ãèšå®ããããšã¯ãã¹ã¯ãªãããJavaScript Moduleãããã¬ãã«å¶äœç©ã«ãã£ãŠè§£éããããããªJavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªããã§ããããšãæå³ããã
"importmap"ãšASCII倧æåã»å°æåäžåºå¥ã§äžèŽãã屿§ãèšå®ããããšã¯ãã¹ã¯ãªãããã¢ãžã¥ãŒã«æå®å解決ã®åäœãå¶åŸ¡ããããã«äœ¿çšãããJSONãå«ãã€ã³ããŒããããã§ããããšãæå³ããã
ãã®å±æ§ã"speculationrules"ãšASCII倧æåã»å°æåäžåºå¥ã§ãããããããã«èšå®ãããšããããšã¯ãã¹ã¯ãªãããspeculation rule setãå®çŸ©ãããã®äžã«speculative loadsèšè¿°ããããã«äœ¿çšãããJSONãå«ãŸããããšãæå³ããã
屿§ãä»ã®å€ã«èšå®ããããšã¯ãã¹ã¯ãªãããããŒã¿ãããã¯ã§ããããšãæå³ãããŠãŒã¶ãŒãšãŒãžã§ã³ãã«ãã£ãŠåŠçãããã®ã§ã¯ãªããèè ã¹ã¯ãªãããŸãã¯ä»ã®ããŒã«ã«ãã£ãŠåŠçããããèè ã¯ãããŒã¿ãããã¯ã瀺ãããã«JavaScript MIMEã¿ã€ããšãã»ã³ã·ã£ã«ãããã§ãªã劥åœãªMIMEã¿ã€ãæååã䜿çšããªããã°ãªããªãã
ããŒã¿ãããã¯ã劥åœãªMIMEã¿ã€ãæååã䜿çšããŠè¡šèšãããªããã°ãªããªãèŠä»¶ã¯ãæœåšçãªå°æ¥ã®è¡çªãåé¿ããããã®å Žæã§ããã"module"ãŸãã¯"importmap"ã®ãããªMIMEã¿ã€ãã§ã¯ãªãtype屿§ã®å€ã¯ããŠãŒã¶ãŒãšãŒãžã§ã³ãã§ç¹å¥ãªåäœãããã¹ã¯ãªããã®ã¿ã€ãã瀺ãããã«æšæºã§äœ¿çšããããçŸåšã«åŠ¥åœãªMIMEã¿ã€ãæååã䜿çšããããšã§ãå°æ¥ã®ãŠãŒã¶ãŒãšãŒãžã§ã³ãã§ããããããŒã¿ãããã¯ãç°ãªãã¹ã¯ãªããã¿ã€ããšããŠåè§£éãããªãããšãä¿èšŒããã
2ã€ç®ã®ã³ã¢å±æ§ã¯src屿§ã§ããããã¯ãã¯ã©ã·ãã¯ã¹ã¯ãªããããã³JavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªããã«å¯ŸããŠã®ã¿æå®ããªããã°ãªãããèŠçŽ ã®åããã¹ãã³ã³ãã³ããã¹ã¯ãªããã³ã³ãã³ããšããŠäœ¿çšãã代ããã«ãæå®ãããURLããã¹ã¯ãªããããã§ãããããããšã瀺ããsrcãæå®ãããå Žåãæœåšçã«ã¹ããŒã¹ã§å²ãŸãã劥åœãªç©ºã§ãªãURLã§ãªããã°ãªããªãã
æå®ãããscriptèŠçŽ ã«æå®ã§ãããã®ä»ã®å±æ§ã¯ã次ã®è¡šã«ãã£ãŠæ±ºãŸãïŒ
nomodule | async | defer | blocking | crossorigin | referrerpolicy | integrity | fetchpriority | |
|---|---|---|---|---|---|---|---|---|
| External classic scripts | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Inline classic scripts | Yes | · | · | · | Yes* | Yes* | · | ·â |
| External module scripts | · | Yes | · | Yes | Yes | Yes | Yes | Yes |
| Inline module scripts | · | Yes | · | · | Yes* | Yes* | · | ·â |
| Import maps | · | · | · | · | · | · | · | · |
| Speculation rules | · | · | · | · | · | · | · | · |
| Data blocks | · | · | · | · | · | · | · | · |
* ã€ã³ã©ã€ã³ã¹ã¯ãªããã«ã¯åæãã§ããããªãããã€ã³ã©ã€ã³ã¹ã¯ãªããã®crossoriginããã³referrerpolicy屿§ã¯ãåçimport()ãå«ãã¢ãžã¥ãŒã«ã€ã³ããŒãã§äœ¿çšãããcredentials modeããã³referrerpolicyã«åœ±é¿ããã
â crossoriginããã³referrerpolicyãšã¯ç°ãªããfetchpriorityã¯ã¢ãžã¥ãŒã«ã®ã€ã³ããŒãã«åœ±é¿ããªããSee some discussion in issue #10276.
ã€ã³ã©ã€ã³scriptèŠçŽ ããŸãã¯å€éšã¹ã¯ãªãããªãœãŒã¹ã®ã³ã³ãã³ãã¯ãããããã¯ã©ã·ãã¯ã¹ã¯ãªããããã³JavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªããã«å¯ŸããJavaScript仿§ã®ScriptãŸãã¯Moduleçæç©ã®èŠä»¶ã«é©åããªããã°ãªããªãã[JAVASCRIPT]
ã€ã³ããŒããããã®ã€ã³ã©ã€ã³scriptèŠçŽ ã®ã³ã³ãã³ãã¯ãã€ã³ããŒããããã®ãªãŒãµãªã³ã°èŠä»¶ã«é©åããªããã°ãªããªãã
ææ©ã«ãŒã«ã»ããã®ã€ã³ã©ã€ã³scriptèŠçŽ ã®ã³ã³ãã³ãã¯ãææ©ã«ãŒã«ã»ããã®ãªãŒãµãªã³ã°èŠä»¶ã«é©åããªããã°ãªããªãã
ããŒã¿ãããã¯ãå«ããããã«äœ¿çšãããå ŽåãããŒã¿ã¯ãã€ã³ã©ã€ã³ã«åã蟌ãŸããªããã°ãªãããããŒã¿ã®åœ¢åŒã¯ãtype屿§ã䜿çšããŠæå®ããªããã°ãªããããã€scriptèŠçŽ ã®ã³ã³ãã³ãã¯ã䜿çšããã圢åŒã®ããã«å®çŸ©ãããèŠä»¶ã«é©åããªããã°ãªããªãã
nomodule屿§ã¯ãã¢ãžã¥ãŒã«ã¹ã¯ãªããããµããŒããããŠãŒã¶ãŒãšãŒãžã§ã³ãã§ã¹ã¯ãªãããå®è¡ãããªãããã«ããçåœå±æ§ã§ãããããã¯ãäžèšã«ç€ºãããã«ãã¢ãã³ãªãŠãŒã¶ãŒãšãŒãžã§ã³ãã®ã¢ãžã¥ãŒã«ã¹ã¯ãªãããšå€ããŠãŒã¶ãŒãšãŒãžã§ã³ãã®ã¯ã©ã·ãã¯ã¹ã¯ãªããã®éžæçãªå®è¡ãå¯èœã«ããã
Support in all current engines.
Support in all current engines.
asyncããã³defer屿§ã¯ãã©ã®ããã«ã¹ã¯ãªãããè©äŸ¡ãããã¹ããã瀺ãçåœå±æ§ã§ãããã¹ã¯ãªããã®ã¿ã€ãã«å¿ããŠããããã®å±æ§ã䜿çšããŠéžæã§ããè€æ°ã®å¯èœãªã¢ãŒããååšããã
å€éšã®ã¯ã©ã·ãã¯ã¹ã¯ãªããã§ã¯ãasync屿§ãååšããå Žåãã¯ã©ã·ãã¯ã¹ã¯ãªããã¯è§£æçšã«äžŠè¡ããŠãã§ããããã䜿çšå¯èœã«ãªããšããã«è©äŸ¡ãããïŒè§£æãå®äºããåã«è¡ãããå¯èœæ§ãããïŒãasyncãååšããªããdefer屿§ãååšããå Žåãã¯ã©ã·ãã¯ã¹ã¯ãªããã¯ã䞊è¡ããŠãã§ãããããããŒãžãè§£æçµäºãããšãã«è©äŸ¡ãããããããã®å±æ§ãååšããªãå Žåãã¹ã¯ãªããã¯ãäž¡æ¹ãå®äºãããŸã§è§£æã黿¢ããŠãããã«ãã§ããããè©äŸ¡ãããã
ã¢ãžã¥ãŒã«ã¹ã¯ãªããã«ã€ããŠãasync屿§ãååšããå Žåãã¢ãžã¥ãŒã«ã¹ã¯ãªãããšãã®ãã¹ãŠã®äŸåé¢ä¿ã¯ãæ§æè§£æãšäžŠè¡ããŠãã§ãããããã¢ãžã¥ãŒã«ã¹ã¯ãªããã¯å©çšå¯èœã«ãªããšããã«ïŒæœåšçã«æ§æè§£æãå®äºããåã«ïŒè©äŸ¡ããããããã§ãªããã°ãã¢ãžã¥ãŒã«ã¹ã¯ãªãããšãã®äŸåé¢ä¿ã¯ãæ§æè§£æãšäžŠè¡ããŠãã§ãããããããŒãžãè§£æçµäºãããšãã«è©äŸ¡ããããïŒdefer屿§ã¯ãã¢ãžã¥ãŒã«ã¹ã¯ãªããã«åœ±é¿ããªããïŒ
ããã¯ãæ¬¡ã®æš¡åŒå³ã«ãã¹ãŠèŠçŽãããïŒ
ããã屿§ã®æ£ç¢ºãªåŠçã®è©³çްã¯ãäž»ã«æŽå²çãªçç±ãããããã¶ãèªæã§ãªããå€ãã®HTMLã®åŽé¢ãå«ãããããã£ãŠãå®è£
èŠæ±ã¯å¿
ç¶çã«ä»æ§ã®ããããå Žæã«æ£åšããŠãããThe algorithms below describe the core of this processing, but these algorithms reference and are referenced by the parsing rules for script start and end tags in HTML, in foreign content, and in XML, the rules for the document.write() method, the handling of scripting, etc.
document.write()ã¡ãœããã䜿çšããŠæ¿å
¥ãããšããéåžžã¯scriptèŠçŽ ãå®è¡ãããïŒäžè¬ã«ãã¹ã¯ãªããã®å®è¡ãŸãã¯HTMLã®è§£æããããã¯ããïŒãinnerHTML屿§ãšouterHTML屿§ã䜿çšããŠæ¿å
¥ããå Žåããããã¯äžåå®è¡ãããªãã
ããšãasync屿§ãæå®ãããŠããããã©ã«ããšãªãããããã³ã°åäœã®ä»£ããã«deferã®åäœããã©ãŒã«ããã¯ããããã«ãdeferã®ã¿ããµããŒãããïŒãã€asyncããµããŒãããªãïŒã¬ã¬ã·ãŒãŠã§ããã©ãŠã¶ãŒããããããããdefer屿§ã¯æå®ãããŠãããã
blocking屿§ã¯ããããã³ã°å±æ§ã§ããã
crossorigin屿§ã¯CORSèšå®å±æ§ã§ãããå€éšã¯ã©ã·ãã¯ã¹ã¯ãªããã®å Žåãã¹ã¯ãªãããä»ã®çæå
ããååŸããããšãããšã©ãŒæ
å ±ã衚瀺ãããã©ãããå¶åŸ¡ãããå€éšã¢ãžã¥ãŒã«ã¹ã¯ãªããã®å Žåãç°ãªãçæå
ã§ããã°ãã¢ãžã¥ãŒã«ãœãŒã¹ã®åæãã§ããã«äœ¿çšãããè³æ Œã¢ãŒããå¶åŸ¡ãããã¯ã©ã·ãã¯ãšã¢ãžã¥ãŒã«ã¹ã¯ãªãããšã®äž¡æ¹ã§ãç°ãªãçæå
ã®ã¢ãžã¥ãŒã«ã®ã€ã³ããŒãã«äœ¿çšãããè³æ Œæ
å ±ã¢ãŒããå¶åŸ¡ããã
ã¯ã©ã·ãã¯ã¹ã¯ãªãããšã¯ç°ãªããã¢ãžã¥ãŒã«ã¹ã¯ãªããã¯ãçæå ããŸããã ãã§ããã®ããã«CORSãããã³ã«ã䜿çšããå¿ èŠãããã
referrerpolicy屿§ã¯ããªãã¡ã©ãŒããªã·ãŒå±æ§ã§ãããããã¯ãå€éšã¹ã¯ãªããã®åæãã§ãããšãã€ã³ããŒããããã¢ãžã¥ãŒã«ã¹ã¯ãªããã®ãã§ããã«äœ¿çšããããªãã¡ã©ãŒããªã·ãŒãèšå®ããã[REFERRERPOLICY]
ã€ã³ããŒããããã¹ã¯ãªããããã§ãããããšãã«äœ¿çšãããŠãããä»ã®ãµããªãœãŒã¹ãååŸããŠããªããšãã«äœ¿çšãããŠããscriptã®ãªãã¡ã©ãŒããªã·ãŒã®äŸïŒ
< script referrerpolicy = "origin" >
fetch( '/api/data' ); // not fetched with <script>'s referrer policy
import ( './utils.mjs' ); // is fetched with <script>'s referrer policy ("origin" in this case)
</ script >
integrity屿§ã¯ãå€éšã¹ã¯ãªããã®åæãã§ããã«äœ¿çšãããå®å
šæ§ã¡ã¿ããŒã¿ãèšå®ããããã®å€ã¯integrity屿§ã®èŠä»¶ã«ãããããªããã°ãªããªãã[SRI]
fetchpriorityã¯ããã§ããåªå
åºŠå±æ§ã§ãããå€éšã¹ã¯ãªããã®åæãã§ããã«äœ¿çšãããåªå
é äœãèšå®ããã
Changing any of these attributes dynamically has no direct effect; these attributes are only used at specific times described in the processing model.
The crossOrigin IDL attribute must reflect the crossorigin content attribute, limited to only known values.
HTMLScriptElement/referrerPolicy
Support in all current engines.
The referrerPolicy IDL attribute must reflect the referrerpolicy content attribute, limited to only known values.
The fetchPriority IDL attribute must reflect the fetchpriority content attribute, limited to only known values.
The async getter steps are:
If this's force async is true, then return true.
If this's async content attribute is present, then return true.
falseãè¿ãã
The async setter steps are:
script.text [ = value ]èŠçŽ ã®åããã¹ãã³ã³ãã³ããè¿ãã
script.text = valueèŠçŽ ã®åãvalueã§æå®ãããããã¹ãã«çœ®ãæããã
HTMLScriptElement.supports(type)æå®ãããtypeããŠãŒã¶ãŒãšãŒãžã§ã³ãã«ãã£ãŠãµããŒããããã¹ã¯ãªããã¿ã€ãã§ããå Žåãtrueãè¿ãããã®ä»æ§ã§å¯èœãªã¹ã¯ãªããã¿ã€ãã¯"classic"ã"module"ããã³"importmap"ã§ããããå°æ¥çã«ä»ã®ã¿ã€ãã远å ãããå¯èœæ§ãããã
The text getter steps are to return this's child text content.
The text setter steps are to string replace all with the given value within this.
HTMLScriptElement/supports_static
Support in all current engines.
The static supports(type) method steps are:
typeåŒæ°ã¯ããããã®å€ãšæ£ç¢ºã«äžèŽããå¿
èŠããããASCII倧æåã»å°æåäžåºå¥äžèŽã¯å®è¡ããªããããã¯ãtypeã³ã³ãã³ã屿§å€ã®åŠçæ¹æ³ãããã³DOMTokenListã®supports()ã¡ãœããã®åäœãšã¯ç°ãªãããWorker()ã³ã³ã¹ãã©ã¯ã¿ãŒã§äœ¿çšãããWorkerTypeåæäœãšäžèŽããã
次ã®äŸã«ãããŠã2ã€ã®scriptèŠçŽ ã䜿çšãããã1ã€ã¯å€éšã®ã¯ã©ã·ãã¯ã¹ã¯ãªãããåã蟌ã¿ããã1ã€ã¯ããŒã¿ãããã¯ã®ãããªããã€ãã®ããŒã¿ãå«ãã
< script src = "game-engine.js" ></ script >
< script type = "text/x-game-map" >
........ U......... e
o............ A.... e
..... A..... AAA.... e
. A.. AAA... AAAAA... e
</ script >
ãã®å Žåã®ããŒã¿ã¯ããããªã²ãŒã ã®ããããçæããã¹ã¯ãªããã«ãã£ãŠäœ¿çšããããããããªããããããããŒã¿ã¯ãã®ããã«äœ¿çšããå¿ èŠã¯ãªããããããå®éã«ãããããŒã¿ã¯ãããŒãžã®ããŒã¯ã¢ããã®ä»ã®éšåã«åã蟌ãŸããŠãããããã§ããŒã¿ãããã¯ã¯ãã²ãŒã ãããã§ç¹å®ã®æ©èœãæ¢ããŠãããŠãŒã¶ãŒãæ¯æŽãããµã€ãã®æ€çŽ¢ãšã³ãžã³ã«ãã£ãŠåã«äœ¿çšãããã
次ã®ãµã³ãã«ã¯ãscriptèŠçŽ ãå€éšã¢ãžã¥ãŒã«ã¹ã¯ãªãããå«ããããã«äœ¿çšãããæ¹æ³ã瀺ãããŸãããã©ãŒã ã®åºåãåæåããå Žåã«ãææžãè§£æãããŠããéã«scriptèŠçŽ ãã¹ã¯ãªãããåŒã³åºãããã«äœ¿çšããããæ¹æ³ã瀺ãã
< script >
function calculate( form) {
var price = 52000 ;
if ( form. elements. brakes. checked)
price += 1000 ;
if ( form. elements. radio. checked)
price += 2500 ;
if ( form. elements. turbo. checked)
price += 5000 ;
if ( form. elements. sticker. checked)
price += 250 ;
form. elements. result. value = price;
}
</ script >
< form name = "pricecalc" onsubmit = "return false" onchange = "calculate(this)" >
< fieldset >
< legend > Work out the price of your car</ legend >
< p > Base cost: £52000.</ p >
< p > Select additional options:</ p >
< ul >
< li >< label >< input type = checkbox name = brakes > Ceramic brakes (£1000)</ label ></ li >
< li >< label >< input type = checkbox name = radio > Satellite radio (£2500)</ label ></ li >
< li >< label >< input type = checkbox name = turbo > Turbo charger (£5000)</ label ></ li >
< li >< label >< input type = checkbox name = sticker > "XZ" sticker (£250)</ label ></ li >
</ ul >
< p > Total: £< output name = result ></ output ></ p >
</ fieldset >
< script >
calculate( document. forms. pricecalc);
</ script >
</ form >
次ã®ãµã³ãã«ã¯ãscriptèŠçŽ ãå€éšJavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªãããå«ããããã«äœ¿çšãããæ¹æ³ã瀺ãã
< script type = "module" src = "app.mjs" ></ script >
ãã®ã¢ãžã¥ãŒã«ãããã³ãã®ãã¹ãŠã®äŸåé¢ä¿ïŒãœãŒã¹ãã¡ã€ã«å
ã®JavaScript importæãéããŠè¡šçŸãããïŒã¯ããã§ããããããäžåºŠãå
šäœã®çµæãšããŠã¢ãžã¥ãŒã«ã°ã©ããã€ã³ããŒãããããã€ææžãè§£æãå®äºããããapp.mjsã®ã³ã³ãã³ãã¯è©äŸ¡ãããã
ããã«ãåãWindowå
ã®ä»ã®scriptèŠçŽ ããã®ã³ãŒããapp.mjsããã¢ãžã¥ãŒã«ãã€ã³ããŒãããå ŽåïŒããšãã°import "./app.mjs";çµç±ã§ïŒãããæ©ãscriptèŠçŽ ã«ãã£ãŠäœæãããåãJavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªãããã€ã³ããŒããããã
次ã®äŸã¯ãã¢ãã³ãªãŠãŒã¶ãŒãšãŒãžã§ã³ãçšã®JavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªãããšå€ããŠãŒã¶ãŒãšãŒãžã§ã³ãçšã®ã¯ã©ã·ãã¯ã¹ã¯ãªãããå«ããæ¹æ³ã瀺ããŠããïŒ
< script type = "module" src = "app.mjs" ></ script >
< script nomodule defer src = "classic-app-bundle.js" ></ script >
JavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªããããµããŒãããã¢ãã³ãªãŠãŒã¶ãŒãšãŒãžã§ã³ãã§ã¯ãnomodule屿§ãæã€scriptèŠçŽ ã¯ç¡èŠããã"module"ã®typeããã€scriptèŠçŽ ããã§ãããããè©äŸ¡ãããïŒã¢ãžã¥ãŒã«ã¹ã¯ãªãããšããŠïŒãéã«ãå€ããŠãŒã¶ãŒãšãŒãžã§ã³ãã¯ã"module"ã®typeããã€scriptèŠçŽ ãããã®ã¹ã¯ãªããã¿ã€ããæªç¥ã®ãã®ãšããŠç¡èŠããããnomodule屿§ãå®è£
ããªããããä»ã®scriptèŠçŽ ãïŒã¯ã©ã·ãã¯ã¹ã¯ãªãããšããŠïŒãã§ããããŠè©äŸ¡ããããšã¯åé¡ãªãã
次ã®ãµã³ãã«ã¯ãscriptèŠçŽ ãïŒããšãã°ãã¥ãŒã¹ãµã€ãäžã§ïŒããé¢çœãèªæžäœéšãçã¿åºãããã«ãææžã®ããã¹ãã§å€æ°ã®çœ®æãè¡ãã€ã³ã©ã€ã³JavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªãããæžãããã«äœ¿çšããããšãã§ããæ¹æ³ã瀺ãïŒ[XKCD1288]
< script type = "module" >
import { walkAllTextNodeDescendants } from "./dom-utils.mjs" ;
const substitutions = new Map([
[ "witnesses" , "these dudes I know" ]
[ "allegedly" , "kinda probably" ]
[ "new study" , "Tumblr post" ]
[ "rebuild" , "avenge" ]
[ "space" , "spaaace" ]
[ "Google glass" , "Virtual Boy" ]
[ "smartphone" , "Pokédex" ]
[ "electric" , "atomic" ]
[ "Senator" , "Elf-Lord" ]
[ "car" , "cat" ]
[ "election" , "eating contest" ]
[ "Congressional leaders" , "river spirits" ]
[ "homeland security" , "Homestar Runner" ]
[ "could not be reached for comment" , "is guilty and everyone knows it" ]
]);
function substitute( textNode) {
for ( const [ before, after] of substitutions. entries()) {
textNode. data = textNode. data. replace( new RegExp( `\\b ${ before} \\b` , "ig" ), after);
}
}
walkAllTextNodeDescendants( document. body, substitute);
</ script >
JavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªããã䜿çšããŠåŸãããããã€ãã®æ³šç®ãã¹ãæ©èœã¯ãä»ã®JavaScriptã¢ãžã¥ãŒã«ãããã©ã«ãã§strictã¢ãŒããããã³ãããã¬ãã«å®£èšãã°ããŒãã«ãªããžã§ã¯ãã«æ°ããããããã£ãå°å
¥ããªãæ¹æ³ãã颿°ãã€ã³ããŒãããæ©èœãå«ããäž¡æ¹ã®ææžã®è§£æãå®äºããããã³ãã®äŸåé¢ä¿ïŒdom-utils.mjsïŒããã§ãããããã€è©äŸ¡ããããŸã§ããã®scriptèŠçŽ ãææžã«è¡šç€ºãããããåãããè©äŸ¡ãããªãããšã«ã泚æããã
次ã®äŸã¯ãJSONã¢ãžã¥ãŒã«ã¹ã¯ãªãããJavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªããå ããã€ã³ããŒãããæ¹æ³ã瀺ãïŒ
< script type = "module" >
import peopleInSpace from "http://api.open-notify.org/astros.json" with { type: "json" };
const list = document. querySelector( "#people-in-space" );
for ( const { craft, name } of peopleInSpace. people) {
const li = document. createElement( "li" );
li. textContent = ` ${ name} / ${ craft} ` ;
list. append( li);
}
</ script >
ã¢ãžã¥ãŒã«ã¹ã¯ãªããã®MIMEã¿ã€ããã§ãã¯ã¯å³å¯ã§ãããJSONã¢ãžã¥ãŒã«ã¹ã¯ãªããã®ãã§ãããæåãããããã«ãHTTPã¬ã¹ãã³ã¹ãJSON MIMEã¿ã€ãïŒContent-Type: text/jsonãªã©ïŒãæããªããã°ãªããªããäžæ¹ãã¹ããŒãã¡ã³ãã®with { type: "json" }ã®éšåãçç¥ãããå ŽåãJavaScriptã¢ãžã¥ãŒã«ã¹ã¯ãªãããã€ã³ããŒãããããšãç®çã§ãããšã¿ãªãããHTTPã¬ã¹ãã³ã¹ãJavaScript MIMEã¿ã€ãã§ãªãMIMEã¿ã€ããæã€å Žåã«ãã§ããã倱æããã
A script element has several associated pieces of state.
A script element has a parser document, which is either null or a Document, initially null. It is set by the HTML parser and the XML parser on script elements they insert, and affects the processing of those elements. script elements with non-null parser documents are known as parser-inserted.
A script element has a preparation-time document, which is either null or a Document, initially null. It is used to prevent scripts that move between documents during preparation from executing.
A script element has a force async boolean, initially true. It is set to false by the HTML parser and the XML parser on script elements they insert, and when the element gets an async content attribute added.
A script element has a from an external file boolean, initially false. It is determined when the script is prepared, based on the src attribute of the element at that time.
A script element has a ready to be parser-executed boolean, initially false. This is used only used for elements that are also parser-inserted, to let the parser know when to execute the script.
A script element has an already started boolean, initially false.
A script element has a delaying the load event boolean, initially false.
A script element has a type, which is either null, "classic", "module", "importmap", or "speculationrules", initially null. It is determined when the element is prepared, based on the type attribute of the element at that time.
A script element has a result, which is either "uninitialized", null (representing an error), a script, an import map parse result, or a speculation rules parse result. It is initially "uninitialized".
A script element has steps to run when the result is ready, which are a series of steps or null, initially null. To mark as ready a script element el given a result:
Set el's result to result.
If el's steps to run when the result is ready are not null, then run them.
Set el's steps to run when the result is ready to null.
Set el's delaying the load event to false.
A script element el is implicitly potentially render-blocking if el's type is "classic", el is parser-inserted, and el does not have an async or defer attribute.
The cloning steps for script elements given node, copy, and subtree are to set copy's already started to node's already started.
When an async attribute is added to a script element el, the user agent must set el's force async to false.
Whenever a script element el's delaying the load event is true, the user agent must delay the load event of el's preparation-time document.
The script HTML element post-connection steps, given insertedNode, are:
If insertedNode is parser-inserted, then return.
Prepare the script element given insertedNode.
The HTML element post-connection steps only run when the inserted element is still connected, which protects against cases where an earlier-inserted script removes a later-inserted script. For instance:
< script >
const script1 = document. createElement( 'script' );
script1. innerText = `
document.querySelector('#script2').remove();
` ;
const script2 = document. createElement( 'script' );
script2. id = 'script2' ;
script2. textContent = `console.log('script#2 running')` ;
document. body. append( script1, script2);
</ script >
Nothing is printed to the console in this example. By the time the HTML element post-connection steps run for the first script that was atomically inserted by append(), it can observe that the second script is already connected to the DOM, and it removes it from the DOM. Because the second script is no longer connected, its HTML element post-connection steps do not run, and it does not get prepared.
The script HTML element removing steps given removedNode are:
If removedNode's result is a speculation rules parse result:
Unregister speculation rules given removedNode's relevant global object and removedNode's result.
Set removedNode's already started to false.
Set removedNode's result to null.
The script children changed steps given changedNode are:
Run the script HTML element post-connection steps, given changedNode.
This has an interesting implication on the execution order of a script element and any newly-inserted child script elements. æ¬¡ã®æçãèããŠã¿ãïŒ
< script id = outer-script ></ script >
< script >
const outerScript = document. querySelector( '#outer-script' );
const start = new Text( 'console.log(1);' );
const innerScript = document. createElement( 'script' );
innerScript. textContent = `console.log('inner script executing')` ;
const end = new Text( 'console.log(2);' );
outerScript. append( start, innerScript, end);
// Logs:
// 1
// 2
// inner script executing
</ script >
By the time the second script block executes, the outer-script has already been prepared, but because it is empty, it did not execute and therefore is not marked as already started. The atomic insertion of the Text nodes and nested script element have the following effects:
All three child nodes get atomically inserted as children of outer-script; all of their insertion steps run, which have no observable consequences in this case.
The outer-script's children changed steps run, which prepares that script; because its body is now non-empty, this executes the contents of the two Text nodes, in order.
The script HTML element post-connection steps finally run for innerScript, causing its body to execute.
The following attribute change steps, given element, localName, oldValue, value, and namespace, are used for all script elements:
If namespace is not null, then return.
If localName is src, value is not null, and element is connected, then run the script HTML element post-connection steps, given element.
To prepare the script element given a script element el:
If el's already started is true, then return.
Let parser document be el's parser document.
Set el's parser document to null.
This is done so that if parser-inserted script elements fail to run when the parser tries to run them, e.g. because they are empty or specify an unsupported scripting language, another script can later mutate them and cause them to run again.
If parser document is non-null and el does not have an async attribute, then set el's force async to true.
This is done so that if a parser-inserted script element fails to run when the parser tries to run it, but it is later executed after a script dynamically updates it, it will execute in an async fashion even if the async attribute isn't set.
Let source text be el's child text content.
If el has no src attribute, and source text is the empty string, then return.
If el is not connected, then return.
If any of the following are true:
el has a type attribute whose value is the empty string;
el has no type attribute but it has a language attribute and that attribute's value is the empty string; or
then let the script block's type string for this script element be "text/javascript".
Otherwise, if el has a type attribute, then let the script block's type string be the value of that attribute with leading and trailing ASCII whitespace stripped.
Otherwise, el has a non-empty language attribute; let the script block's type string be the concatenation of "text/" and the value of el's language attribute.
The language attribute is never conforming, and is always ignored if there is a type attribute present.
If the script block's type string is a JavaScript MIME type essence match, then set el's type to "classic".
Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "module", then set el's type to "module".
Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "importmap", then set el's type to "importmap".
Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "speculationrules", then set el's type to "speculationrules".
Otherwise, return. (No script is executed, and el's type is left as null.)
If parser document is non-null, then set el's parser document back to parser document and set el's force async to false.
Set el's already started to true.
Set el's preparation-time document to its node document.
If parser document is non-null, and parser document is not equal to el's preparation-time document, then return.
If scripting is disabled for el, then return.
The definition of scripting is disabled means that, amongst others, the following scripts will not execute: scripts in XMLHttpRequest's responseXML documents, scripts in DOMParser-created documents, scripts in documents created by XSLTProcessor's transformToDocument feature, and scripts that are first inserted by a script into a Document that was created using the createDocument() API. [XHR] [DOMPARSING] [XSLTP] [DOM]
If el has a nomodule content attribute and its type is "classic", then return.
This means specifying nomodule on a module script has no effect; the algorithm continues onward.
Let cspType be "script speculationrules" if el's type is "speculationrules"; otherwise, "script".
If el does not have a src content attribute, and the Should element's inline behavior be blocked by Content Security Policy? algorithm returns "Blocked" when given el, cspType, and source text, then return. [CSP]
If el has an event attribute and a for attribute, and el's type is "classic":
Let for be the value of el's for attribute.
Let event be the value of el's event attribute.
Strip leading and trailing ASCII whitespace from event and for.
If for is not an ASCII case-insensitive match for the string "window", then return.
If event is not an ASCII case-insensitive match for either the string "onload" or the string "onload()", then return.
If el has a charset attribute, then let encoding be the result of getting an encoding from the value of the charset attribute.
If el does not have a charset attribute, or if getting an encoding failed, then let encoding be el's node document's the encoding.
If el's type is "module", this encoding will be ignored.
Let classic script CORS setting be the current state of el's crossorigin content attribute.
Let module script credentials mode be the CORS settings attribute credentials mode for el's crossorigin content attribute.
Let cryptographic nonce be el's [[CryptographicNonce]] internal slot's value.
If el has an integrity attribute, then let integrity metadata be that attribute's value.
Otherwise, let integrity metadata be the empty string.
Let referrer policy be the current state of el's referrerpolicy content attribute.
Let fetch priority be the current state of el's fetchpriority content attribute.
Let parser metadata be "parser-inserted" if el is parser-inserted, and "not-parser-inserted" otherwise.
Let options be a script fetch options whose cryptographic nonce is cryptographic nonce, integrity metadata is integrity metadata, parser metadata is parser metadata, credentials mode is module script credentials mode, referrer policy is referrer policy, and fetch priority is fetch priority.
Let settings object be el's node document's relevant settings object.
If el has a src content attribute:
If el's type is "importmap" or "speculationrules", then queue an element task on the DOM manipulation task source given el to fire an event named error at el, and return.
External import maps and speculation rules are not currently supported. See WICG/import-maps issue #235 and WICG/nav-speculation issue #348 for discussions on adding support.
Let src be the value of el's src attribute.
If src is the empty string, then queue an element task on the DOM manipulation task source given el to fire an event named error at el, and return.
Set el's from an external file to true.
Let url be the result of encoding-parsing a URL given src, relative to el's node document.
If url is failure, then queue an element task on the DOM manipulation task source given el to fire an event named error at el, and return.
If el is potentially render-blocking, then block rendering on el.
Set el's delaying the load event to true.
If el is currently render-blocking, then set options's render-blocking to true.
Let onComplete given result be the following steps:
Mark as ready el given result.
Switch on el's type:
classic"Fetch a classic script given url, settings object, options, classic script CORS setting, encoding, and onComplete.
module"If el does not have an integrity attribute, then set options's integrity metadata to the result of resolving a module integrity metadata with url and settings object.
Fetch an external module script graph given url, settings object, options, and onComplete.
For performance reasons, user agents may start fetching the classic script or module graph (as defined above) as soon as the src attribute is set, instead, in the hope that el will become connected (and that the crossorigin attribute won't change value in the meantime). Either way, once el becomes connected, the load must have started as described in this step. If the UA performs such prefetching, but el never becomes connected, or the src attribute is dynamically changed, or the crossorigin attribute is dynamically changed, then the user agent will not execute the script so obtained, and the fetching process will have been effectively wasted.
If el does not have a src content attribute:
Let base URL be el's node document's document base URL.
Switch on el's type:
classic"Let script be the result of creating a classic script using source text, settings object, base URL, and options.
Mark as ready el given script.
module"Set el's delaying the load event to true.
If el is potentially render-blocking:
Block rendering on el.
Set options's render-blocking to true.
Fetch an inline module script graph, given source text, base URL, settings object, options, and with the following steps given result:
Queue an element task on the networking task source given el to perform the following steps:
Mark as ready el given result.
Queueing a task here means that, even if the inline module script has no dependencies or synchronously results in a parse error, we won't proceed to execute the script element synchronously.
importmap"Let result be the result of creating an import map parse result given source text and base URL.
Mark as ready el given result.
speculationrules"Let result be the result of creating a speculation rules parse result given source text and el's node document.
Mark as ready el given result.
If el's type is "classic" and el has a src attribute, or el's type is "module":
If el has an async attribute or el's force async is true:
Let scripts be el's preparation-time document's set of scripts that will execute as soon as possible.
Append el to scripts.
Set el's steps to run when the result is ready to the following:
Remove el from scripts.
Otherwise, if el is not parser-inserted:
Let scripts be el's preparation-time document's list of scripts that will execute in order as soon as possible.
Append el to scripts.
Set el's steps to run when the result is ready to the following:
If scripts[0] is not el, then abort these steps.
While scripts is not empty, and scripts[0]'s result is not "uninitialized":
Execute the script element scripts[0].
Remove scripts[0].
Otherwise, if el has a defer attribute or el's type is "module":
Append el to its parser document's list of scripts that will execute when the document has finished parsing.
Set el's steps to run when the result is ready to the following: set el's ready to be parser-executed to true. (The parser will handle executing the script.)
Otherwise:
Set el's parser document's pending parsing-blocking script to el.
Block rendering on el.
Set el's steps to run when the result is ready to the following: set el's ready to be parser-executed to true. (The parser will handle executing the script.)
Otherwise:
If all of the following are true:
classic";then:
Set el's parser document's pending parsing-blocking script to el.
Set el's ready to be parser-executed to true. (The parser will handle executing the script.)
Otherwise, immediately execute the script element el, even if other scripts are already executing.
Each Document has a pending parsing-blocking script, which is a script element or null, initially null.
Each Document has a set of scripts that will execute as soon as possible, which is a set of script elements, initially empty.
Each Document has a list of scripts that will execute in order as soon as possible, which is a list of script elements, initially empty.
Each Document has a list of scripts that will execute when the document has finished parsing, which is a list of script elements, initially empty.
If a script element that blocks a parser gets moved to another Document before it would normally have stopped blocking that parser, it nonetheless continues blocking that parser until the condition that causes it to be blocking the parser no longer applies (e.g., if the script is a pending parsing-blocking script because the original Document has a style sheet that is blocking scripts when it was parsed, but then the script is moved to another Document before the blocking style sheet(s) loaded, the script still blocks the parser until the style sheets are all loaded, at which time the script executes and the parser is unblocked).
To execute the script element given a script element el:
Let document be el's node document.
If el's preparation-time document is not equal to document, then return.
Unblock rendering on el.
If el's result is null, then fire an event named error at el, and return.
If el's from an external file is true, or el's type is "module", then increment document's ignore-destructive-writes counter.
Switch on el's type:
classic"Let oldCurrentScript be the value to which document's currentScript object was most recently set.
If el's root is not a shadow root, then set document's currentScript attribute to el. Otherwise, set it to null.
This does not use the in a document tree check, as el could have been removed from the document prior to execution, and in that scenario currentScript still needs to point to it.
Run the classic script given by el's result.
Set document's currentScript attribute to oldCurrentScript.
module"Assert: document's currentScript attribute is null.
Run the module script given by el's result.
importmap"Register an import map given el's relevant global object and el's result.
speculationrules"Register speculation rules given el's relevant global object and el's result.
Decrement the ignore-destructive-writes counter of document, if it was incremented in the earlier step.
If el's from an external file is true, then fire an event named load at el.
User agents are not required to support JavaScript. This standard needs to be updated if a language other than JavaScript comes along and gets similar wide adoption by web browsers. Until such a time, implementing other languages is in conflict with this standard, given the processing model defined for the script element.
ãµãŒããŒã¯ãUpdates to ECMAScript Media Typesã«åŸã£ãŠãJavaScriptãªãœãŒã¹ã«text/javascriptã䜿çšãã¹ãã§ããããµãŒããŒã¯ãJavaScriptãªãœãŒã¹ã«ä»ã®JavaScript MIMEã¿ã€ãã䜿çšãã¹ãã§ã¯ãªããéJavaScript MIMEã¿ã€ãã䜿çšããŠã¯ãªããªãã[RFC9239]
For external JavaScript resources, MIME type parameters in `Content-Type` headers are generally ignored. (In some cases the `charset` parameter has an effect.) However, for the script element's type attribute they are significant; it uses the JavaScript MIME type essence match concept.
For example, scripts with their type attribute set to "text/javascript; charset=utf-8" will not be evaluated, even though that is a valid JavaScript MIME type when parsed.
Furthermore, again for external JavaScript resources, special considerations apply around `Content-Type` header processing as detailed in the prepare the script element algorithm and Fetch. [FETCH]
scriptèŠçŽ ã®ã³ã³ãã³ãã®å¶çŽãã®ç¯ã§èª¬æãããããªãå¥åŠãªå¶çŽãåé¿ããæãç°¡åã§å®å
šãªæ¹æ³ã¯ããããã®ã·ãŒã±ã³ã¹ãã¹ã¯ãªããå
ã§ãªãã©ã«ïŒããšãã°æååãæ£èŠè¡šçŸããŸãã¯ã³ã¡ã³ããªã©ïŒã«åºçŸãããšããASCII倧æåã»å°æåäžåºå¥ã®äžèŽã§"<!--"ã"<\!--"ã«ã"<script"ã"<\script"ã«ãããã³"</script"ã"<\/script"ã«åžžã«ãšã¹ã±ãŒãããåŒã®äžã§ãã®ãããªæ§é äœã䜿çšããã³ãŒããèšè¿°ããªãããã«ããããšã§ããããã®ç¯ã®å¶éãããªã¬ãŒã«ãªããããèœãšã穎ãåé¿ããïŒããªãã¡ãæŽå²çãªçç±ã®ããã«ãHTMLã«ãããscriptãããã¯ã®è§£æã¯ããããã®ã·ãŒã±ã³ã¹ãèããå Žåã«çŽèгçã§ãªãåããããå¥åŠã§é¢šå€ãããªæ
£ç¿ã§ããã
scriptèŠçŽ ã®åå«ããã¹ãã³ã³ãã³ãã¯ãUnicodeã®æåã»ããã§ããæ¬¡ã®ABNFã®scriptçæç©ãšäžèŽããªããã°ãªããªãã[ABNF]
script = outer * ( comment-open inner comment-close outer )
outer = < any string that doesn 't contain a substring that matches not-in-outer >
not-in-outer = comment-open
inner = < any string that doesn 't contain a substring that matches not-in-inner >
not-in-inner = comment-close / script-open
comment-open = "<!--"
comment-close = "-->"
script-open = "<" s c r i p t tag-end
s = %x0053 ; U+0053 LATIN CAPITAL LETTER S
s =/ %x0073 ; U+0073 LATIN SMALL LETTER S
c = %x0043 ; U+0043 LATIN CAPITAL LETTER C
c =/ %x0063 ; U+0063 LATIN SMALL LETTER C
r = %x0052 ; U+0052 LATIN CAPITAL LETTER R
r =/ %x0072 ; U+0072 LATIN SMALL LETTER R
i = %x0049 ; U+0049 LATIN CAPITAL LETTER I
i =/ %x0069 ; U+0069 LATIN SMALL LETTER I
p = %x0050 ; U+0050 LATIN CAPITAL LETTER P
p =/ %x0070 ; U+0070 LATIN SMALL LETTER P
t = %x0054 ; U+0054 LATIN CAPITAL LETTER T
t =/ %x0074 ; U+0074 LATIN SMALL LETTER T
tag-end = %x0009 ; U+0009 CHARACTER TABULATION (tab)
tag-end =/ %x000A ; U+000A LINE FEED (LF)
tag-end =/ %x000C ; U+000C FORM FEED (FF)
tag-end =/ %x0020 ; U+0020 SPACE
tag-end =/ %x002F ; U+002F SOLIDUS (/)
tag-end =/ %x003E ; U+003E GREATER-THAN SIGN (>)
scriptèŠçŽ ãã¹ã¯ãªããææžãå«ãå Žåãäžèšã®ç¯ã§èšè¿°ãããããã«ãèŠçŽ ã®ã³ã³ãã³ãã®ãããªãå¶çŽãããã
次ã®ã¹ã¯ãªããã¯ããã®åé¡ã瀺ããŠããããã®ããã«ãæååãå«ãŸããŠããã¹ã¯ãªããããããšããïŒ
const example = 'Consider this string: <!-- <script>' ;
console. log( example);
ãããscriptãããã¯ã§çŽæ¥ãã®æååãå
¥ããŠããå Žåãäžèšã®å¶éã«éåããªãã
< script >
const example = 'Consider this string: <!-- <script>' ;
console. log( example);
</ script >
ãããããã倧ããªåé¡ãã€ãã¹ã¯ãªããããããã®å¶éã«éåããªãçç±ã¯ãå®éã«ã¹ã¯ãªãããå¥åŠã«è§£æãããã ãããšããããšã§ãããäžèšã®ã¹ã¯ãªãããããã¯ã¯çµäºããŠããªããããã¯ãå®éã«ã¯äŸç¶ãšããŠscriptãããã¯ã®äžéšã§ãããã®ã¹ããããã«ãããŠ"</script>"çµäºã¿ã°ã®ããã«èŠãããã®ã§ãããïŒã¹ã¯ãªãããçµäºããŠããªãããïŒã¹ã¯ãªããã¯å®è¡ããªããã¹ã¯ãªãããäœããã®åœ¢ã§å®è¡ããå Žåãæ¬¡ã®ããã«ããŒã¯ã¢ãããèŠããå ŽåãïŒããã§åŒ·èª¿ãããïŒã¹ã¯ãªããã劥åœãªJavaScriptã§ãªãã®ã§ãã¹ã¯ãªããã¯å€±æããã ããïŒ
< script >
const example = 'Consider this string: <!-- <script>' ;
console. log( example);
</ script >
<!-- despite appearances, this is actually part of the script still! -->
< script >
... // this is the same script block still...
</ script >
ããã§èµ·ãã£ãŠããããšã¯ã¬ã¬ã·ãŒãªçç±ã®ããã«ãHTMLã«ãããscriptèŠçŽ ã§"<!--"ããã³"<script"æååã¯ãããŒãµãŒããããã¯ãéããæ€èšããããã«ãã©ã³ã¹ããšãå¿
èŠãããã
ãã®ç¯ã®æåã«è¿°ã¹ãããã«ãåé¡ã®æååããšã¹ã±ãŒãããããšã«ãã£ãŠãåé¡ã¯å®å šã«åé¿ãããŠããïŒ
< script >
// Note: `\x3C` is an escape sequence for `<`.
const example = 'Consider this string: \x3C!-- \x3Cscript>' ;
console. log( example);
</ script >
<!-- this is just a comment between script blocks -->
< script >
... // this is a new script block
</ script >
次ã®äŸã®ããã«ããããã®ã·ãŒã±ã³ã¹ã¯èªç¶ã«ã¹ã¯ãªããåŒã§åºçŸå¯èœã§ããïŒ
if ( x<!-- y) { ... }
if ( player< script ) { ... }
ãã®ãããªå Žåãæåã¯ãšã¹ã±ãŒãããããšã¯ã§ããªãããã·ãŒã±ã³ã¹ãçºçããªãããã«åŒã¯æ¬¡ã®ããã«æžãæããããšãã§ããïŒ
if ( x < !-- y) { ... }
if ( !-- y > x) { ... }
if ( ! ( -- y) > x) { ... }
if ( player < script) { ... }
if ( script > player) { ... }
ãããè¡ããšã¯ãŸããåæ§ã«æ§ã ãªèœãšã穎ãåé¿ããïŒé¢é£ããæŽå²çãªçç±ã®ããã«ãã¯ã©ã·ãã¯ã¹ã¯ãªããã§æåå"<!--"ã¯ã"//"ã®ããã«ãå®éã«ã¯è¡ã³ã¡ã³ãã®éå§ãšããŠæ±ãããã
scriptèŠçŽ ã®src屿§ãæå®ãããå Žåãããããã°ãscriptèŠçŽ ã®ã³ã³ãã³ãã¯ãèŠçŽ ã®ã³ã³ãã³ãããåå²ããããããªtext IDL屿§å€ã§ãªããã°ãªãããæåã»ãããUnicodeã§ããäžèšã®ABNFã§documentationçæç©ãšäžèŽããªããã°ãªããªãã[ABNF]
documentation = * ( * ( space / tab / comment ) [ line-comment ] newline )
comment = slash star * ( not-star / star not-slash ) 1* star slash
line-comment = slash slash * not-newline
; characters
tab = %x0009 ; U+0009 CHARACTER TABULATION (tab)
newline = %x000A ; U+000A LINE FEED (LF)
space = %x0020 ; U+0020 SPACE
star = %x002A ; U+002A ASTERISK (*)
slash = %x002F ; U+002F SOLIDUS (/)
not-newline = %x0000-0009 / %x000B-10FFFF
; a scalar value other than U+000A LINE FEED (LF)
not-star = %x0000-0029 / %x002B-10FFFF
; a scalar value other than U+002A ASTERISK (*)
not-slash = %x0000-002E / %x0030-10FFFF
; a scalar value other than U+002F SOLIDUS (/)
ããã¯ãJavaScriptã®ã³ã¡ã³ãã§èŠçŽ ã®ã³ã³ãã³ããèšçœ®ãããã®ãšäžèŽããã
ãã®èŠæ±ã¯ãscriptèŠçŽ ã®ã³ã³ãã³ãã®æ§æäžã«å
ã®å¶çŽã«å ããŠååšããã
以äžã¯ãäŸç¶ãšããŠå€éšã¹ã¯ãªãããã¡ã€ã«ãåç
§ããéã«ææžå
ã§ãèè
ãã©ã€ã»ã³ã¹æ
å ±ãAPIæ
å ±ã®ãããªææžãå«ãããšãèš±å¯ãããsrc屿§ãæäŸããäžæ¹ã§ãå¶ç¶ã«ãèè
ãæå¹ãªã¹ã¯ãªããã®ããã«èŠãããã®ãå«ãŸãªãããã«ãæ§æã¯å¶çŽãããã
< script src = "cool-effects.js" >
// create new instances using:
// var e = new Effect();
// start the effect using .play, stop using .stop:
// e.play();
// e.stop();
</ script >
script elements and XSLTAvoid using client-side XSLT in browsers. The browser implementations of XSLT are highly susceptible to memory safety vulnerabilities, and the web platform has evolved toward JavaScript as the safe replacement. For these reasons, this feature is in the process of being removed from the web platform. ïŒããã¯äœå¹Žããããé·ãããã»ã¹ã§ãããïŒ
ãã®ç¯ã¯éèŠç¯çã§ããã
This specification does not define how XSLT interacts with the script element. However, in the absence of another specification actually defining this, here are some guidelines for implementers, based on existing implementations:
When an XSLT transformation program is triggered by an <?xml-stylesheet?> processing instruction and the browser implements a direct-to-DOM transformation, script elements created by the XSLT processor need to have its parser document set correctly, and run in document order (modulo scripts marked defer or async), immediately, as the transformation is occurring.
The XSLTProcessor transformToDocument() method adds elements to a Document object with a null browsing context, and, accordingly, any script elements they create need to have their already started set to true in the prepare the script element algorithm and never get executed (scripting is disabled). Such script elements still need to have their parser document set, though, such that their async IDL attribute will return false in the absence of an async content attribute.
The XSLTProcessor transformToFragment() method needs to create a fragment that is equivalent to one built manually by creating the elements using document.createElementNS(). For instance, it needs to create script elements with null parser document and with their already started set to false, so that they will execute when the fragment is inserted into a document.
The main distinction between the first two cases and the last case is that the first two operate on Documents and the last operates on a fragment.
noscriptèŠçŽ Support in all current engines.
noscriptèŠçŽ ãååšããªãå ŽåãHTMLææžã®headèŠçŽ å
ãnoscriptèŠçŽ ãååšããªãå ŽåãHTMLææžã§ãã¬ãŒãžã³ã°ã³ã³ãã³ããæåŸ
ãããå ŽæãnoscriptèŠçŽ ããªãå ŽåãselectèŠçŽ ãŸãã¯optgroupèŠçŽ ã®åå«ãšããŠãheadèŠçŽ å
ã§ïŒä»»æã®é ã§ã0å以äžã®linkèŠçŽ ã0å以äžã®styleèŠçŽ ã0å以äžã®metaèŠçŽ ãheadèŠçŽ å€ã§ïŒééçããã ããnoscriptèŠçŽ ã®åå«ãæã£ãŠã¯ãªããªããHTMLElementã䜿çšãããnoscriptèŠçŽ ã¯ãã¹ã¯ãªãããæå¹ã§ããå Žåã¯äœã衚ãããã¹ã¯ãªãããç¡å¹ã§ããå Žåã¯èŠçŽ ã®åã衚ããããã¯ãææžãè§£æãããæ¹æ³ã«åœ±é¿ãäžããããšã«ãã£ãŠãã¹ã¯ãªããããµããŒããããŠãŒã¶ãŒãšãŒãžã§ã³ããšãµããŒãããªããŠãŒã¶ãŒãšãŒãžã§ã³ãã«ç°ãªãããŒã¯ã¢ãããæç€ºããããã«äœ¿çšãããã
HTMLææžã§äœ¿çšããå Žåãèš±å¯ãããã³ã³ãã³ãã¢ãã«ã¯æ¬¡ã®ãšããïŒ
headèŠçŽ å
ã®noscriptèŠçŽ ã«å¯ŸããŠnoscriptèŠçŽ ã¯ãlinkãstyleãããã³metaèŠçŽ ã®ã¿ãå«ãŸãªããã°ãªããªãã
headèŠçŽ å
ã®noscriptèŠçŽ ã«å¯ŸããŠnoscriptèŠçŽ ã¯ãããã¹ãã®ã¿ãå«ãŸãªããã°ãªããªãããã ããcontextèŠçŽ ãšããŠnoscriptèŠçŽ ããã€HTMLæçè§£æã¢ã«ãŽãªãºã ãåŒã³åºãããã€inputãšããŠããã¹ãã³ã³ãã³ããåŒã³åºããšãnoscriptèŠçŽ ã®åã§ãã£ãå Žåã«é©åããã ãããlinkãstyleãmetaèŠçŽ ã®ã¿ãããªãããŒãã®ãªã¹ãããããããªããã°ãªããããã€è§£æãšã©ãŒã§ãªãå Žåãé€ãã
headèŠçŽ å€ã®noscriptèŠçŽ ã«å¯ŸããŠnoscriptèŠçŽ ã®ã³ã³ãã³ãã¢ãã«ã¯ééçã§ãããåæã«noscriptèŠçŽ ãnoscriptèŠçŽ ãæã£ãŠã¯ãªããªãïŒnoscriptèŠçŽ ãå
¥ãåã«ã§ããªãïŒè¿œå å¶éãããã
headèŠçŽ å€ã®noscriptèŠçŽ ã«å¯ŸããŠnoscriptèŠçŽ ã¯ããã¹ãã®ã¿ãå«ãŸãªããã°ãªããªãããã ãããã¹ãã¯ã次ã®ã¢ã«ãŽãªãºã ãnoscriptèŠçŽ ããã³scriptèŠçŽ ããããªãé©åææžããããããã®ã§ãªããã°ãªãããã¢ã«ãŽãªãºã ã§ã¹ãããã¯äŸå€ãæãããŸãã¯HTMLããŒãµãŒã«è§£æãšã©ãŒãèµ·ãããªãããã«ããªããã°ãªããªãïŒ
scriptèŠçŽ ãåãé€ããnoscriptèŠçŽ ã®ãªã¹ããäœãããã®ãªã¹ãã®ånoscriptèŠçŽ ã«å¯ŸããŠã次ã®ã¹ããããå®è¡ããïŒnoscriptèŠçŽ èŠçŽ ã®åããã¹ãã³ã³ãã³ããšãããnoscriptèŠçŽ ã®outerHTML屿§ãsã®å€ã«èšå®ãããïŒããã¯ãå¯äœçšãšããŠnoscriptèŠçŽ ãææžããé€å»ããããïŒæŽå²çãªçç±ã«ãããããŒãµãŒãåŒã³åºããããšãã«ã¹ã¯ãªããã¢ãŒããç¡å¹ãã©ããã«åºã¥ãHTMLããŒãµãŒã«ãã£ãŠnoscriptèŠçŽ ãç°ãªãæ¹æ³ã§åŠçãããã®ã§ããããã®ãã¹ãŠã®ããã€ããå¿
èŠãšãããã
noscriptã¯XMLææžã§äœ¿çšããŠã¯ãªããªãã
noscriptèŠçŽ ã¯HTMLæ§æã§ã®ã¿æå¹ã ããXMLæ§æã§ã¯å¹æããªããã¹ã¯ãªãããæå¹ã§ããå Žåããã®èŠçŽ ãåäœããæ¹æ³ã¯ãåºæ¬çã«ããŒãµãŒã"ãªã"ã«ããããšã§ãããèŠçŽ ã®å
容ã¯ãå®éã®èŠçŽ ãšããŠã§ã¯ãªãçŽç²ã«ããã¹ããšããŠæ±ãããŠããã®ã§ãããXMLã¯ããããå®è¡ããããã®ã¡ã«ããºã ãå®çŸ©ããªãã
The noscript element has no other requirements. In particular, children of the noscript element are not exempt from form submission, scripting, and so forth, even when scripting is enabled for the element.
次ã®äŸã«ãããŠãnoscriptèŠçŽ ã¯ãã¹ã¯ãªããã®ãã©ãŒã«ããã¯ãæäŸããããã«äœ¿çšãããã
< form action = "calcSquare.php" >
< p >
< label for = x > Number</ label > :
< input id = "x" name = "x" type = "number" >
</ p >
< script >
var x = document. getElementById( 'x' );
var output = document. createElement( 'p' );
output. textContent = 'Type a number; it will be squared right then!' ;
x. form. appendChild( output);
x. form. onsubmit = function () { return false ; }
x. oninput = function () {
var v = x. valueAsNumber;
output. textContent = v + ' squared is ' + v * v;
};
</ script >
< noscript >
< input type = submit value = "Calculate Square" >
</ noscript >
</ form >
ã¹ã¯ãªãããç¡å¹ã§ããå Žåããã¿ã³ã¯ããµãŒããŒåŽã§èšç®ãè¡ãããã«è¡šç€ºããããã¹ã¯ãªãããæå¹ã§ããå Žåã代ããã«å€ããã®å Žã§èšç®ãããã
noscriptèŠçŽ ã¯éåšã§ãããæã«ã¯ãã¹ã¯ãªãããæå¹ã«ãããããããªãããäœããã®çç±ã§ããŒãžã®ã¹ã¯ãªããã倱æãããããããªãããã®ãããªçç±ãããæ¬¡ã®äŸã®ããã«ãnoscriptèŠçŽ ã®äœ¿çšãé¿ãã代ããã«ããã®å Žã§ã¹ã¯ãªããã®ãªãããŒãžããã¹ã¯ãªããåãããããŒãžã«ããŒãžã倿Žããã¹ã¯ãªãããèšèšããããšãäžè¬ã«ããè¯ãïŒ
< form action = "calcSquare.php" >
< p >
< label for = x > Number</ label > :
< input id = "x" name = "x" type = "number" >
</ p >
< input id = "submit" type = submit value = "Calculate Square" >
< script >
var x = document. getElementById( 'x' );
var output = document. createElement( 'p' );
output. textContent = 'Type a number; it will be squared right then!' ;
x. form. appendChild( output);
x. form. onsubmit = function () { return false ; }
x. oninput = function () {
var v = x. valueAsNumber;
output. textContent = v + ' squared is ' + v * v;
};
var submit = document. getElementById( 'submit' );
submit. parentNode. removeChild( submit);
</ script >
</ form >
äžèšã®ææ³ã¯ãnoscriptãèš±å¯ãããŠããªããããXMLææžã§ã圹ã«ç«ã€ã
templateèŠçŽ Support in all current engines.
Support in all current engines.
span屿§ãæããªãcolgroupèŠçŽ ã®åãšããŠãfor â æ¢åã®ã³ã³ãã³ããæŽæ°ããshadowrootmode â 宣èšçãªã·ã£ããŠã«ãŒãã®ã¹ããªãŒãã³ã°ãæå¹ã«ããshadowrootdelegatesfocus â 宣èšçãªã·ã£ããŠã«ãŒãã«ä»£çãã©ãŒã«ã¹ãèšå®ããshadowrootserializable â 宣èšçãªã·ã£ããŠã«ãŒãã«ã·ãªã¢ã©ã€ãºå¯èœãèšå®ããshadowrootslotassignment â 宣èšçãªã·ã£ããŠã«ãŒãã«ã¹ãããå²ãåœãŠãèšå®ããshadowrootclonable â 宣èšçãªã·ã£ããŠã«ãŒãã«ã¯ããŒã³å¯èœãèšå®ããshadowrootcustomelementregistry â 宣èšçãªã·ã£ããŠã«ãŒããæå¹ã«ããŠãã«ã¹ã¿ã èŠçŽ ã¬ãžã¹ããªã䜿çšããããšã瀺ã[Exposed =Window ]
interface HTMLTemplateElement : HTMLElement {
[HTMLConstructor ] constructor ();
readonly attribute DocumentFragment content ;
[CEReactions , Reflect="for"] attribute DOMString htmlFor ;
[CEReactions ] attribute DOMString shadowRootMode ;
[CEReactions , Reflect ] attribute boolean shadowRootDelegatesFocus ;
[CEReactions , Reflect ] attribute boolean shadowRootSerializable ;
[CEReactions ] attribute DOMString shadowRootSlotAssignment ;
[CEReactions , Reflect ] attribute boolean shadowRootClonable ;
[CEReactions , Reflect ] attribute DOMString shadowRootCustomElementRegistry ;
};
templateèŠçŽ ã¯ãè€è£œãããã¹ã¯ãªããã«ãã£ãŠææžã«æ¿å
¥ã§ããHTMLã®æçã宣èšããããã«äœ¿çšãããã
ã¬ã³ããªã³ã°ã«ãããŠãtemplateèŠçŽ ã¯äœã衚ããªãã
forã³ã³ãã³ã屿§ã¯ãã³ã³ãã³ããæ¿å
¥ããäœçœ®ïŒ<?marker>ïŒããŸãã¯çœ®ãæããç¯å²ã®éå§äœçœ®ïŒ<?start>ïŒã瀺ãProcessingInstructionãèå¥ããããã®å±æ§ãæå®ãããŠããå Žåããã®å±æ§ã®å€ã¯ãtemplateèŠçŽ ãšåãããªãŒå
ã«ãã<?marker>ãŸãã¯<?start> ProcessingInstructionã®name屿§ã®å€ãšåãã§ãªããã°ãªããªãã
shadowrootmodeã³ã³ãã³ã屿§ã¯ã次ã®ããŒã¯ãŒãããã³ç¶æ
ããã€åæå±æ§ã§ããïŒ
| ããŒã¯ãŒã | ç¶æ | æŠèŠ |
|---|---|---|
open | Open | templateèŠçŽ ã¯ãéãã宣èšçãªã·ã£ããŠã«ãŒãã衚ãã |
closed | Closed | templateèŠçŽ ã¯ãéãã宣èšçãªã·ã£ããŠã«ãŒãã衚ãã |
shadowrootmode屿§ã®ç¡å¹å€ã®ããã©ã«ãããã³æ¬ æå€ã®ããã©ã«ãã¯ãäž¡æ¹ãšãnoneç¶æ
ã§ããã
shadowrootdelegatesfocusã³ã³ãã³ã屿§ã¯ãçåœå±æ§ã§ããã
shadowrootserializableã³ã³ãã³ã屿§ã¯ãçåœå±æ§ã§ããã
shadowrootslotassignmentã³ã³ãã³ã屿§ã¯ã次ã®ããŒã¯ãŒãããã³ç¶æ
ããã€åæå±æ§ã§ããïŒ
| ããŒã¯ãŒã | ç¶æ | æŠèŠ |
|---|---|---|
named | Named | 宣èšåã·ã£ããŠã«ãŒãã¯ãååä»ãã¹ãããå²ãåœãŠã䜿çšããã |
manual | Manual | 宣èšçãªã·ã£ããŠã«ãŒãã¯ãæåã®ã¹ãããå²ãåœãŠã䜿çšããã |
shadowrootslotassignment屿§ã®äžæ£å€ã®ããã©ã«ããšæ¬ æå€ã®ããã©ã«ãã®äž¡æ¹ã¯ãNamedç¶æ
ã§ããã
shadowrootclonableã³ã³ãã³ã屿§ã¯ãçåœå±æ§ã§ããã
shadowrootcustomelementregistryã³ã³ãã³ã屿§ã¯ãçåœå±æ§ã§ããã
templateèŠçŽ ã®ãã³ãã¬ãŒãã³ã³ãã³ãã¯ãèŠçŽ èªäœã®åã§ã¯ãªãã
DOMæäœã®çµæãšããŠãtemplateèŠçŽ ãTextããŒããšèŠçŽ ããŒããå«ãããšãå¯èœã§ããããããããã®èŠçŽ ã®ã³ã³ãã³ãã¢ãã«ã¯nothingãšããŠå®çŸ©ãããããããã¹ãŠã®ãã®ã¯templateèŠçŽ ã®ã³ã³ãã³ãã¢ãã«ã«éåããã
ããšãã°ãæ¬¡ã®ææžãèããŠã¿ãïŒ
<!doctype html>
< html lang = "en" >
< head >
< title > Homework</ title >
< body >
< template id = "template" >< p > Smile!</ p ></ template >
< script >
let num = 3 ;
const fragment = document. getElementById( 'template' ). content. cloneNode( true );
while ( num-- > 1 ) {
fragment. firstChild. before( fragment. firstChild. cloneNode( true ));
fragment. firstChild. textContent += fragment. lastChild. textContent;
}
document. body. appendChild( fragment);
</ script >
</ html >
templateã«ãããpèŠçŽ ã¯ãDOMå
ã®templateã®åã§ã¯ãªããtemplateèŠçŽ ã®content IDL屿§ã«ãã£ãŠè¿ãããDocumentFragmentã®åã§ããã
ã¹ã¯ãªãããtemplateèŠçŽ ã®appendChild()ãåŒã³åºããšãïŒä»ã®èŠçŽ ã®å Žåãšåæ§ã«ïŒtemplateèŠçŽ ã«åèŠçŽ ã远å ãããããããããã®ããã«ããããšã¯ãtemplateèŠçŽ ã®ã³ã³ãã³ãã¢ãã«ã«éåããããšã«ãªãã
template.contentSupport in all current engines.
ãã³ãã¬ãŒãã³ã³ãã³ãïŒDocumentFragmentïŒãè¿ãã
Each template element has an associated DocumentFragment object that is its template contents. The template contents have no conformance requirements. When a template element is created, the user agent must run the following steps to establish the template contents:
Let document be the template element's node document's appropriate template contents owner document.
Create a DocumentFragment object whose node document is document and host is the template element.
Set the template element's template contents to the newly created DocumentFragment object.
A Document document's appropriate template contents owner document is the Document returned by the following algorithm:
If document is not a Document created by this algorithm:
If document does not yet have an associated inert template document:
Let newDocument be the result of creating a document that implements Document, given document's relevant realm; its browsing context is null. This is "a Document created by this algorithm" for the purposes of the step above.
If document is an HTML document, then mark newDocument as an HTML document also.
Set document's associated inert template document to newDocument.
Set document to document's associated inert template document.
Each Document not created by this algorithm thus gets a single Document to act as its proxy for owning the template contents of all its template elements, so that they aren't in a browsing context and thus remain inert (e.g. scripts do not run). Meanwhile, template elements inside Document objects that are created by this algorithm just reuse the same Document owner for their contents.
Return document.
Each template element has an associated Element-or-DocumentFragment-or-null insertion target, which is initially null.
Each template element has an associated ProcessingInstruction-or-null insertion start marker and insertion end marker, which are initially null.
The adopting steps (with node and oldDocument as parameters) for template elements are the following:
Let document be node's node document's appropriate template contents owner document.
node's node document is the Document object that node was just adopted into.
Adopt node's template contents (a DocumentFragment object) into document.
The content getter steps are:
Assert: this's template contents is not a ShadowRoot node.
Return this's template contents.
The shadowRootMode IDL attribute must reflect the shadowrootmode content attribute, limited to only known values.
The shadowRootSlotAssignment IDL attribute must reflect the shadowrootslotassignment content attribute, limited to only known values.
The shadowRootCustomElementRegistry IDL attribute intentionally does not have a boolean type so it can be extended.
The cloning steps for template elements given node, copy, and subtree are:
If subtree is false, then return.
For each child of node's template contents's children, in tree order: clone a node given child with document set to copy's template contents's node document, subtree set to true, and parent set to copy's template contents.
To prepare content patching given an Element or DocumentFragment scope and a template element template:
Let markerName be template's for attribute's value.
If markerName is the empty string, then return false.
Let (start, end) be the result of find markers given scope and markerName.
If start is null, then return false.
Set template's insertion target to start's parent.
Set template's insertion start marker to start.
Set template's insertion end marker to end.
If start is end, then return true.
Let removedNodes be an empty list.
Let currentNode be start's next sibling.
While currentNode is not null:
If currentNode is end, then break.
Append currentNode to removedNodes.
Set currentNode to currentNode's next sibling.
For each node of removedNodes:
Return true.
To find markers given a node scope and a string name:
For each descendant of scope's descendants, in tree order:
If descendant is not a ProcessingInstruction node, then continue.
If the result of getting a processing instruction attribute given descendant and "name" is not name, then continue.
If descendant's target is "marker", then return (descendant, descendant).
If descendant's target is "start":
Let start be descendant.
Let nestingLevel be 0.
Let sibling be start's next sibling.
While sibling is not null:
If sibling is a ProcessingInstruction node:
Set sibling to sibling's next sibling.
Return (start, null).
No matching <?end> was found, which is interpreted as a range from start to the end of its parent.
Return (null, null).
ãã®äŸã«ãããŠãã¹ã¯ãªããã¯ãæåã§ããŒã¯ã¢ããããæ§é ãçæãã代ããã«èŠçŽ æ§é ãæäŸããããã«templateã䜿çšããŠãããŒã¿æ§é ããããŒã¿ããã€ããŒãã«4åã«æå
¥ããã
<!DOCTYPE html>
< html lang = 'en' >
< title > Cat data</ title >
< script >
// Data is hard-coded here, but could come from the server
var data = [
{ name: 'Pillar' , color: 'Ticked Tabby' , sex: 'Female (neutered)' , legs: 3 },
{ name: 'Hedral' , color: 'Tuxedo' , sex: 'Male (neutered)' , legs: 4 },
];
</ script >
< table >
< thead >
< tr >
< th > Name < th > Color < th > Sex < th > Legs
< tbody >
< template id = "row" >
< tr >< td >< td >< td >< td >
</ template >
</ table >
< script >
var template = document. querySelector( '#row' );
for ( var i = 0 ; i < data. length; i += 1 ) {
var cat = data[ i];
var clone = template. content. cloneNode( true );
var cells = clone. querySelectorAll( 'td' );
cells[ 0 ]. textContent = cat. name;
cells[ 1 ]. textContent = cat. color;
cells[ 2 ]. textContent = cat. sex;
cells[ 3 ]. textContent = cat. legs;
template. parentNode. appendChild( clone);
}
</ script >
ãã®äŸã¯ãtemplateã®ã³ã³ãã³ãã«cloneNode()ã䜿çšãããããã¯ãåãããšãããdocument.importNode()ãç䟡çã«äœ¿çšããããšãã§ãããããŒãææžãæŽæ°ããããšãã«ããã®2ã€ã®APIã®å¯äžã®éãããããããŒããappendChild()ã§ä»å ãããå Žåã«cloneNode()ãšãšãã«æŽæ°ãããããŒããã¯ããŒã³åããããšãã«ãdocument.importNode()ãšãšãã«æŽæ°ãããã
ãã®äŸã§ã¯ãããŒãžã®ã¡ã€ã³ã³ã³ãã³ããé
ä¿¡ãããåŸãfor屿§ããã€templateèŠçŽ ã䜿çšããŠselectèŠçŽ ã«åœã®ãªã¹ããåã蟌ãã
<!DOCTYPE html>
< html lang = "en" >
< head >
< title > Out-of-order countries</ title >
< style >
# countries : empty {
opacity : 0 ;
}
</ style >
</ head >
< body >
< select id = countries > <?marker name="country-options"?> </ select >
...
< template for = "country-options" >< option > Antigua</ option > ...</ template >
</ body >
</ html >
<?marker?>åŠçåœä»€ã¯ãåŸã®templateèŠçŽ ã®optionèŠçŽ ã«çœ®ãæãããããselectèŠçŽ ã¯ãå€ãèšå®ããããŸã§ééçã§ããã
ãã®äŸã§ã¯ãfor屿§ããã€templateèŠçŽ ã䜿çšãããŠãããææžãé äžåã§ã¹ããªãŒãã³ã°ããããã«ããŸãé«éãªéçã³ã³ãã³ããéãããããŠãµãŒããŒäžã§éåæçã«å©çšå¯èœã«ãªã£ãæç¹ã§èšç®ãããæšå¥šæ
å ±ãéä¿¡ããŠããã
<!DOCTYPE html>
< html lang = "en" >
< head >
< title > Async recommendation engine</ title >
< style >
aside {
/* position the aside where it can grow without causing layout shift or obscuring other content */
}
aside : has ( . placeholder ) {
/* style the placeholder content */
}
</ style >
</ head >
< body >
< h1 > How to train your cat</ h1 >
< p > Set realistic goals and don't expect your cat to make a perfect cup of tea
on the first try.</ p >
< aside >
< p > Recommended reading:</ p >
<?start name="recommended">
< ul class = "placeholder" >
< li > ...</ li >
< li > ...</ li >
< li > ...</ li >
</ ul >
<?end>
</ aside >
< p > ...</ p >
< p > Now sit back and enjoy your tea with your cat.</ p >
<!-- The server has a potentially long delay at this point. -->
< template for = "recommended" >
< ul >
< li > Cat or butler, which is right for you?</ li >
< li > Rewarding good cat behavior</ li >
< li > Kettles considered harmful</ li >
</ ul >
</ template >
</ body >
</ html >
<?start name="recommended">ãš<?end>ãšã®éã®ã³ã³ãã³ãã¯ã templateã®ã³ã³ãã³ãã«çœ®ãæãããããæ°ããã³ã³ãã³ãã¯class="placeholder"ã䜿çšããªãããããã¬ãŒã¹ãã«ããŒã®ã¹ã¿ã€ã«ã¯é©çšãããªããªãã
template elements with XSLT and XPathAvoid using client-side XSLT in browsers. The browser implementations of XSLT are highly susceptible to memory safety vulnerabilities, and the web platform has evolved toward JavaScript as the safe replacement. For these reasons, this feature is in the process of being removed from the web platform. ïŒããã¯äœå¹Žããããé·ãããã»ã¹ã§ãããïŒ
ãã®ç¯ã¯éèŠç¯çã§ããã
This specification does not define how XSLT and XPath interact with the template element. However, in the absence of another specification actually defining this, here are some guidelines for implementers, which are intended to be consistent with other processing described in this specification:
An XSLT processor based on an XML parser that acts as described in this specification needs to act as if template elements contain as descendants their template contents for the purposes of the transform.
An XSLT processor that outputs a DOM needs to ensure that nodes that would go into a template element are instead placed into the element's template contents.
XPath evaluation using the XPath DOM API when applied to a Document parsed using the HTML parser or the XML parser described in this specification needs to ignore template contents.
slotèŠçŽ Support in all current engines.
Support in all current engines.
name â ã·ã£ããŠããªãŒã¹ãããã®åå[Exposed =Window ]
interface HTMLSlotElement : HTMLElement {
[HTMLConstructor ] constructor ();
[CEReactions , Reflect ] attribute DOMString name ;
sequence <Node > assignedNodes (optional AssignedNodesOptions options = {});
sequence <Element > assignedElements (optional AssignedNodesOptions options = {});
undefined assign ((Element or Text )... nodes );
};
dictionary AssignedNodesOptions {
boolean flatten = false ;
};
slotèŠçŽ ã¯ãã¹ããããå®çŸ©ãããå
žåçã«ã·ã£ããŠããªãŒã«äœ¿çšããããããããã°ãslotèŠçŽ ã¯ãã®å²ãåœãŠãããããŒãã衚ããããã§ãªããã°ãã®ã³ã³ãã³ãã衚ãã
nameã³ã³ãã³ã屿§ã¯ãä»»æã®æååå€ãå«ãã§ããããããã¯ã¹ãããã®ååã衚ãã
slot屿§ã¯ãå¥ã®èŠçŽ ã«ã¹ããããå²ãåœãŠãããã«äœ¿çšãããïŒname屿§ããã€slotèŠçŽ ã¯ããã®èŠçŽ ããã®name屿§ã®å€ãšäžèŽããå€ãæã€slot屿§ãæã¡ããã€slotèŠçŽ ããã®å¯Ÿå¿ããslot屿§å€ãæã€ã«ãŒãã®ãã¹ããæã€ã·ã£ããŠããªãŒã®åã§ããå Žåãä»»æã®èŠçŽ ãå²ãåœãŠãããååä»ãã¹ããããäœæããã
slot.nameSupport in all current engines.
slot.assignedNodes()Support in all current engines.
slot.assignedNodes({ flatten: true })slotèŠçŽ ãååšããªããªããŸã§ãååž°çã«ãslotèŠçŽ ã«ééããã®ãšåããã®ãè¿ããslot.assignedElements()HTMLSlotElement/assignedElements
Support in all current engines.
slot.assignedElements({ flatten: true })assignedNodes({ flatten: true })ãšåããã®ãè¿ããslot.assign(...nodes)slotã®æåã§å²ãåœãŠãããããŒãããæå®ãããnodesã«èšå®ããã
slotèŠçŽ ã¯ãmanually assigned nodesãæã¡ãããã¯ã assign()ã«ãã£ãŠèšå®ãããslottablesã®é åºä»ãã»ããã§ããããã®ã»ããã¯ãæåã¯ç©ºã§ããã
manually assigned nodesã»ããã¯ãã¹ã¯ãªããããçŽæ¥ã¢ã¯ã»ã¹ã§ããªããããslottablesãžã®åŒ±ãåç §ã䜿çšããŠå®è£ ããããšãã§ããã
The assignedNodes(options) method steps are:
If options["flatten"] is false, then return this's assigned nodes.
Return the result of finding flattened slottables with this.
The assignedElements(options) method steps are:
If options["flatten"] is false, then return this's assigned nodes, filtered to contain only Element nodes.
Return the result of finding flattened slottables with this, filtered to contain only Element nodes.
Support in all current engines.
The assign(...nodes) method steps are:
For each node of this's manually assigned nodes, set node's manual slot assignment to null.
Let nodesSet be a new ordered set.
For each node of nodes:
If node's manual slot assignment refers to a slot, then remove node from that slot's manually assigned nodes.
Set node's manual slot assignment to this.
Append node to nodesSet.
Set this's manually assigned nodes to nodesSet.
Run assign slottables for a tree for this's root.