Get the character set used in an external script file:
var x = document.getElementById("myScript").charset
Click the button to return the charset attribute of the script.
<!DOCTYPE html> <html> <body> <script id="myScript" src="javascript.js" charset="UTF-8"></script> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//w ww . j a va 2s . co m var x = document.getElementById("myScript").charset; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The charset property sets or gets the charset attribute of a script.
The charset attribute sets the character encoding for an external script file.
The charset attribute is only for external scripts.
Some common values:
Charset | Meaning |
---|---|
"ISO-8859-1" | Standard encoding for the Latin alphabet |
"UTF-8" | Character encoding for Unicode. |
The charset attribute returns a String representing the charset of the external script file.