YouTip LogoYouTip

Prop Script Charset

## HTML DOM Script charset Property The `charset` property of the HTML DOM Script object returns or sets the character encoding used in an external script file. This property is particularly useful when the character encoding of the external script file differs from the encoding of the HTML document hosting it. > **Note:** The `charset` property is only applicable to external scripts (i.e., when the `src` attribute is present on the `

Click the button to display the character encoding of the external script.

``` **Output:** ```text Script Charset: UTF-8 ``` --- ### Example 2: Dynamically Set the Character Set You can also dynamically assign a character encoding to a script element before it is appended to the document. ```javascript // Create a new script element var newScript = document.createElement("script"); newScript.src = "external-helper.js"; // Set the character encoding to UTF-8 newScript.charset = "UTF-8"; // Append the script to the document head document.head.appendChild(newScript); ``` --- ## Browser Support The `charset` property is widely supported across all major modern and legacy browsers: | Property | Chrome | Edge / IE | Firefox | Safari | Opera | | :--- | :--- | :--- | :--- | :--- | :--- | | **charset** | Yes | Yes | Yes | Yes | Yes | --- ## Important Considerations 1. **Deprecation Warning:** Although widely supported for backward compatibility, the `charset` attribute on the `