Javascript examples for DOM HTML Element:Script
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:
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:
<!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>