English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Referenzhandbuch

Vollständiges Verzeichnis der HTML-Tags

HTML: <script> defer-Attribut

<script> defer ist ein boolesches Attribut, das festlegt, dass das Skript nach der vollständigen Analyse der Seite ausgeführt wird, defer ist nur für externe Skripte geeignet (sollte nur verwendet werden, wenn das src-Attribut vorhanden ist).</script>

 HTML <script> Tag

Online-Beispiel

Skripte, die nach dem Laden der Seite ausgeführt werden:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>HTML: Verwendungsbeispiel von defer-Attribut in script>-Grundlegende Anleitung(oldtoolbag.com)</title> 
</head>
<body>
<script src="demo_script.js" defer></script>
<p>Das obige Skript verlangt Informationen von den folgenden Absätzen. Dies ist in der Regel unmöglich, da das Skript vor der Existenz des Abschnitts ausgeführt wird.</p>
<p id="p1">Hallo Welt! </p>
<p>Die defer-Attribut legt fest, dass das Skript später ausgeführt werden soll. Auf diese Weise kann das Skript Informationen aus dem Abschnitt anfordern.</p>
</body>
</html>
Test it out ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the defer attribute.

Definition and Usage

The defer attribute is a boolean attribute.

If it exists, it specifies that the script should be executed after the page is parsed.

Note: The defer attribute is only applicable to external scripts (it should be used only when the src attribute exists).

Note: External scripts can be executed in various ways:

  • If there is asynchronous: the script is executed asynchronously with the rest of the page (the script will be executed while the page continues to parse)

  • If there is no asynchronous and there is a delay: execute the script after the page is parsed

  • If there is no asynchronous or delay: immediately obtain and execute the script before the browser continues to parse the page

HTML 4.01 With HTML5Differences

None.

Differences between HTML and XHTML

In XHTML, attribute abbreviations are prohibited, the defer attribute must be defined as <script defer="defer">.

Syntax

<script defer>
 HTML <script> Tag