You are here: Reference > JavaScript > client-side > HTML DOM > properties > characterSet (document, XMLDocument)

characterSet property (document, XMLDocument)

Browser support:
9
Returns the character encoding of the document.
The characterSet property is supported in Internet Explorer from version 9. In older versions, you can use the charset property instead.
To get the character set that belongs to the current regional and language settings of the operating system, use the defaultCharset property. Finally, if you need the character encoding used for parsing the document, use the inputEncoding property.

Syntax:

object.characterSet;
You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String that represents the character set. For more information, see the page for character sets.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the characterSet property:
<!DOCTYPE html>
<head>
    <meta charset="utf-8" />
    <script type="text/javascript">
        function GetCharSet () {
            var message = "";

            var docCharSet = document.characterSet ? document.characterSet : document.charset;
            message += "The character encoding of the document: <b>" + docCharSet + "</b><br />";

            if (document.defaultCharset) {
                message += "The character encoding that belongs to the operating system:  <b>" + document.defaultCharset + "</b><br />";
            }
            if (document.inputEncoding) {
                message += "The character encoding used for parsing the document:  <b>" + document.inputEncoding + "</b><br />";
            }

            var info = document.getElementById ("info");
            info.innerHTML = message;
        }
    </script>
</head>
<body onload="GetCharSet ()">
    <div id="info" style="width:500px; background-color:#e0d0d0;"></div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content