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, HTMLAttributionSrcElementUtils
Inheritance
HTMLScriptElement
Implements
Inherited Members

Remarks

-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 blocking property of the HTMLScriptElement interface is a string indicating that certain operations should be blocked on the fetching of the script.

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

Property Value

DOMTokenList

A string. Must be a space-separated list of blocking tokens listed below indicating the operations that are to be blocked:

Remarks

It reflects the blocking attribute of the script element.

-Blocking
-Blocking

See also on MDN

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 fetchpriority attribute of the script element.

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

Property Value

string

A string representing the priority hint. Possible values are:

Remarks

The property allows a developer to signal that fetching a particular script early or late in the loading process has more or less impact on user experience than a browser can reasonably infer when assigning an internal priority.
This in turn allows the browser to increase or decrease the priority, and potentially load the script earlier or later than it would otherwise.
The property should be used sparingly, as excessive or incorrect prioritization can degrade performance.

The fetch priority allows you to decrease the priority of late-body scripts, or to increase the priority of async scripts without having to use preloading.
When early loading of a script is important, the priority can be used to complement preloading, boosting the priority ahead of less-impactful resources that have a higher default priority.

Note that both the internal priority of any fetch operation, and the impact of fetchPriority on the priority, are entirely browser dependent.

-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

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.

[Value("src")]
public string Src { get; set; }

Property Value

string

A string.

Remarks

It reflects the src attribute of the script element.

See also on MDN

Text

The text property of the HTMLScriptElement interface is a string that reflects the text content inside the {{HTMLElement("script")}} element. It acts the same way as the TextContent property.

[Value("text")]
public string Text { get; set; }

Property Value

string

A string.

Remarks

It reflects the text attribute of the script element.

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