[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/API/HTMLScriptElement [Back]  [Original]

HTMLScriptElement - API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

HTMLScriptElement

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

* Some parts of this feature may have varying levels of support.

HTML- <script> HTMLScriptElement , <script> ( HTMLElement ).

JavaScript application/javascript MIME type, , (image/*), (video/*), (audio/*), text/csv. , error; , success.

must be a string

In this article

, HTMLElement.

type String MIME . type.
src String URL . src.
event String , HTML-.
charset String . charset.
async Boolean

async defer , . defer async , src .

:

  1. async , .
  2. async , defer, .
  3. , , .

defer async, , defer ( async) defer .

: , HTML, . , <script> HTML, , XML; document.write(); ; .
defer Boolean
crossOrigin String String, CORS . , , .
text String

IDL text Text <script> ( , ) . , , IDL textContent.

noModule Boolean , ES2015 , JavaScript .
referrerPolicy String String, HTML referrerpolicy , , .

; , HTMLElement.

. , <script> <script>, ( document.currentScript). . defer async.

js
function loadError(oError) {
  throw new URIError(
    "The script " + oError.target.src + " didn't load correctly.",
  );
}

function prefixScript(url, onloadFunction) {
  var newScript = document.createElement("script");
  newScript.onerror = loadError;
  if (onloadFunction) {
    newScript.onload = onloadFunction;
  }
  document.currentScript.parentNode.insertBefore(
    newScript,
    document.currentScript,
  );
  newScript.src = url;
}

, document.currentScript, <head>.

js
function loadError(oError) {
  throw new URIError(
    "The script " + oError.target.src + " didn't load correctly.",
  );
}

function affixScriptToHead(url, onloadFunction) {
  var newScript = document.createElement("script");
  newScript.onerror = loadError;
  if (onloadFunction) {
    newScript.onload = onloadFunction;
  }
  document.head.appendChild(newScript);
  newScript.src = url;
}

:

js
affixScriptToHead("myScript1.js");
affixScriptToHead("myScript2.js", function () {
  alert('The script "myScript2.js" has been correctly loaded.');
});

Specification
HTML
# htmlscriptelement


Web Proxy Viewer  |  New URL  |  Original Page