Table of Contents

Class HTMLScriptElement

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

JavaScript files should be served with the text/javascript MIME type, but browsers are lenient and block them only if the script is served with an image type (image/), video type (video/), audio type (audio/*), or text/csv. If the script is blocked, its element receives an HTMLElementerror event; otherwise, it receives a Windowload event.

[Value("HTMLScriptElement")]
public class HTMLScriptElement : HTMLElement, Region, GeometryUtils, ParentNode, NonDocumentTypeChildNode, ChildNode, Slottable, ARIAMixin, Animatable, ElementCSSInlineStyle, GlobalEventHandlers, ElementContentEditable, HTMLOrSVGElement, HTMLAttributionSrcElementUtils
Inheritance
HTMLScriptElement
Implements
Inherited Members

Remarks

NOTE

When inserted using the Write(params Union58[]) method, {{HTMLElement("script")}} elements execute (typically synchronously), but when inserted using InnerHTML or OuterHTML, they do not execute at all.

-HTML script element
-HTML noscript element
-CurrentScript
-Web Workers (code snippets similar to scripts but executed in another global context)

See also on MDN

Constructors

HTMLScriptElement()

public HTMLScriptElement()

Properties

Async

The async property of the HTMLScriptElement interface is a boolean value that controls how the script should be executed. For classic scripts, if the async property is set to true, the external script will be fetched in parallel to parsing and evaluated as soon as it is available. For module scripts, if the async property is set to true, the script and all their dependencies will be fetched in parallel to parsing and evaluated as soon as they are available.

[Value("async")]
public bool Async { get; set; }

Property Value

bool

A boolean.

Remarks

It reflects the async attribute of the script element.

-Defer

See also on MDN

Blocking

The read-only blocking property of the HTMLScriptElement returns a live DOMTokenList object containing the operations that should be blocked on the fetching of an external resource. It reflects the {{HTMLElement("script")}} element's blocking content attribute.

[Value("blocking")]
public DOMTokenList Blocking { get; }

Property Value

DOMTokenList

A live DOMTokenList object.Although the blocking property itself is read-only in the sense that you can't replace the DOMTokenList object, you can still assign to the blocking property directly, which is equivalent to assigning to its DOMTokenListvalue property. You can also modify the DOMTokenList object using the DOMTokenListadd, DOMTokenListremove, DOMTokenListreplace, and DOMTokenListtoggle methods.

Remarks

Charset

[Value("charset")]
public string Charset { get; set; }

Property Value

string

CrossOrigin

The crossOrigin property of the HTMLScriptElement interface reflects the {{Glossary("CORS", "Cross-Origin Resource Sharing")}} settings for the script element. For classic scripts from other origins, this controls if full error information will be exposed. For module scripts, it controls the script itself and any script it imports. See CORS settings attributes for details.

[Value("crossOrigin")]
public string? CrossOrigin { get; set; }

Property Value

string

A string of a keyword specifying the CORS mode to use when fetching the resource. Possible values are:If the crossOrigin property is specified with any other value, it is the same as specifying it as the anonymous.If the crossOrigin property is not specified, the resource is fetched without CORS (the no-cors {{domxref("Request.mode", "mode", "", "nocode")}} and the same-origin {{domxref("Request.credentials", "credentials", "", "nocode")}} mode).

Remarks

Defer

The defer property of the HTMLScriptElement interface is a boolean value that controls how the script should be executed. For classic scripts, if the defer property is set to true, the external script will be executed after the document has been parsed, but before firing DocumentDOMContentLoaded event. For module scripts, the defer property has no effect.

[Value("defer")]
public bool Defer { get; set; }

Property Value

bool

A boolean.

Remarks

It reflects the defer attribute of the script element.

-Async

See also on MDN

Event

[Value("event")]
public string Event { get; set; }

Property Value

string

FetchPriority

The fetchPriority property of the HTMLScriptElement interface represents a hint to the browser indicating how it should prioritize fetching an external script relative to other external scripts.
It reflects the <script> element's fetchpriority content attribute.

[Value("fetchPriority")]
public string FetchPriority { get; set; }

Property Value

string

A string. For the permitted values, see the HTML fetchpriority attribute.

Remarks

-FetchPriority
-FetchPriority
-HTTP Link header
-Optimize resource loading with the Fetch Priority API for information about how this API affects priorities on Chrome.

See also on MDN

HtmlFor

[Value("htmlFor")]
public string HtmlFor { get; set; }

Property Value

string

Integrity

The integrity property of the HTMLScriptElement interface is a string that contains inline metadata that a browser can use to verify that a fetched resource has been delivered without unexpected manipulation.

[Value("integrity")]
public string Integrity { get; set; }

Property Value

string

A string.

Remarks

It reflects the integrity attribute of the script element.

-Integrity
-Subresource Integrity

See also on MDN

NoModule

The noModule property of the HTMLScriptElement interface is a boolean value that indicates whether the script should be executed in browsers that support ES modules. Practically, this can be used to serve fallback scripts to older browsers that do not support JavaScript modules.

[Value("noModule")]
public bool NoModule { get; set; }

Property Value

bool

A boolean, true means that the script should not be executed in browsers that support ES modules, false otherwise.

Remarks

It reflects the nomodule attribute of the script element.

See also on MDN

ReferrerPolicy

The referrerPolicy property of the
HTMLScriptElement interface reflects the HTML
referrerpolicy of the script element, which defines how the referrer is set when fetching the script and any scripts it imports.

[Value("referrerPolicy")]
public string ReferrerPolicy { get; set; }

Property Value

string

A string; one of the following:

NOTE
An empty string value ("") is both the default
value, and a fallback value if referrerpolicy is not supported. If
referrerpolicy is not explicitly specified on the
<script> element, it will adopt a higher-level referrer policy,
i.e., one set on the whole document or domain. If a higher-level policy is not
available, the empty string is treated as being equivalent to
no-referrer-when-downgrade.

Remarks

Src

WARNING
This property represents the URI of an external script loaded into the script element, which may be executable depending on the script HTMLScriptElementtype.
APIs like this are known as injection sinks, and are potentially a vector for cross-site scripting (XSS) attacks.
[Value("src")]
public string Src { get; set; }

Property Value

string

Getting the property returns a string containing the element's script URI.Setting the property accepts either a TrustedScriptURL object or a string.

Remarks

You can mitigate this risk by having a Content Security Policy (CSP) that restricts the locations from which scripts can be loaded, and by always assigning TrustedScriptURL objects instead of strings and enforcing trusted types.
See Security considerations for more information.

The src property of the HTMLScriptElement interface is a string representing the URL of an external script; this can be used as an alternative to embedding a script directly within a document.

It reflects the src attribute of the script element.

See also on MDN

Text

WARNING
This property represents the text content of a script element, which may be executable depending on the script type.
APIs like this are known as injection sinks, and are potentially a vector for cross-site scripting (XSS) attacks.
[Value("text")]
public string Text { get; set; }

Property Value

string

Getting the property returns a string containing the script's text.Setting the property accepts either a TrustedScript object or a string.

Remarks

You can mitigate this risk by always assigning TrustedScript objects instead of strings and enforcing trusted types.
See Security considerations for more information.

The text property of the HTMLScriptElement interface represents the inline text content of the {{HTMLElement("script")}} element.
It behaves in the same way as the HTMLScriptElement.TextContent and HTMLScriptElement.InnerText property.

-HTMLScriptElement.TextContent
-HTMLScriptElement.InnerText

See also on MDN

Type

The type property of the HTMLScriptElement interface is a string that reflects the type of the script.

[Value("type")]
public string Type { get; set; }

Property Value

string

A string. The value of this property can be one of the following:For more information, please refer to the type attribute of the script element.

Remarks

It reflects the type attribute of the script element.

See also on MDN

Methods

Supports(string)

The supports() static method of the HTMLScriptElement interface provides a simple and consistent method to feature-detect what types of scripts are supported by the user agent.

[Value("supports")]
public static bool Supports(string type)

Parameters

type string

Returns

bool

Returns true if the indicated script type is supported and false otherwise.

Remarks

The method is expected to return true for classic and module scripts, which are supported by most modern browsers.

-HTMLScriptElement
-script
-JavaScript modules
-WorkerWorker constructor

See also on MDN