Script charset Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Script

Description

The charset property sets or gets the charset attribute of a script, which controls the character encoding used in an external script file.

The charset attribute is only for external scripts

Set the charset property with the following Values

Value Description
charset Sets the character encoding of an external script file.

Some common values:

  • "ISO-8859-1" - Standard encoding for the Latin alphabet
  • "UTF-8" - Character encoding for Unicode.

Return Value

A String, representing the URL of the external script file.

The following code shows how to get the character set used in an external script file:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<script id="myScript" src="demo_script_charset.js" charset="UTF-8"></script>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/* w  w w  .j a  va  2 s .  c o  m*/
    var x = document.getElementById("myScript").charset;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials