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

HTMLScriptElement - Web API | MDN

MDN Web Docs

View in English Always switch to English

HTMLScriptElement

*

20157

*

HTML HTMLScriptElement ( HTMLElement <>

HTMLElement

Name Type Description
type String MIME type
src String src
htmlFor String htmlFor
event String HTML DOM JavaScript HTML
charset String charset
async Boolean

async defer bool script src async defer

async async defer useragent

Web

defer Boolean
crossOrigin String CORS
text String

<script> textContent IDL

document.write() <script> innerHTML outerHTML

HTMLElement

importScript <script> <script> document.currentScript script defer async

js
function loadError(oError) {
  throw new URIError("The script " + oError.target.src + " is not accessible.");
}

function importScript(sSrc, fOnload) {
  var oScript = document.createElement("script");
  oScript.type = "text/javascript";
  oScript.onerror = loadError;
  if (fOnload) {
    oScript.onload = fOnload;
  }
  document.currentScript.parentNode.insertBefore(
    oScript,
    document.currentScript,
  );
  oScript.src = sSrc;
}

document.currentScript <head>

js
var importScript = (function (oHead) {
  function loadError(oError) {
    throw new URIError(
      "The script " + oError.target.src + " is not accessible.",
    );
  }

  return function (sSrc, fOnload) {
    var oScript = document.createElement("script");
    oScript.type = "text/javascript";
    oScript.onerror = loadError;
    if (fOnload) {
      oScript.onload = fOnload;
    }
    oHead.appendChild(oScript);
    oScript.src = sSrc;
  };
})(document.head || document.getElementsByTagName("head")[0]);

js
importScript("myScript1.js");
importScript(
  "myScript2.js",
  /* onload function: */ function () {
    alert(
      'You read this alert because the script "myScript2.js" has been correctly loaded.',
    );
  },
);

HTML
# htmlscriptelement


Web Proxy Viewer  |  New URL  |  Original Page