Latest web development tutorials

HTML DOM Script defer property

Script Object Reference Script Object

Examples

Check whether the script is executed when the page is completed Resolution:

var x = document.getElementById("myScript").defer

x The output is:

true

try it"

Definition and Usage

Whether to perform script defer property sets or returns when the page has finished parsing.

This property reflects defer attribute <script> tag.

Note: defer property applies only to external script (only when using the src attribute).

Note: There are several ways to perform an external script:

  • If async = "async": script asynchronously with respect to the rest of the page execution (when the page continues to be parsed, the script will be executed)
  • When the script execution will be completed parsing the page: If you do not use the async and defer = "defer"
  • If neither use nor async defer: Before the browser to continue parsing the page, immediately read and execute scripts

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support defer attribute.

Note: Opera version 12 and earlier are not supported defer property.


grammar

Back defer attributes:

scriptObject .defer

Setting defer properties:

scriptObject .defer=true|false

Property Value

描述
true|false 规定当页面完成解析时是否执行脚本。
  • true - 当页面完成解析时执行脚本。
  • false - 当页面完成解析时不执行脚本。

technical details

return value: Boolean value, if and when the page has finished executing the script parsing, it returns true, otherwise returns false.


related articles

HTML Reference Manual: HTML <Script> the defer attribute


Script Object Reference Script Object