The characterSet property is used to return the character encoding for the document at the time of parsing. It is the character set that has been used for the document rendering also the user can override the encoding. The characterSet property will return null if the document is created in memory.
Syntax:
document.characterSet
Return Value: A String, representing the document’s character encoding
Example:
html
<!DOCTYPE html>
< html >
< head >
< title >DOM characterSet Property</ title >
< style >
h1 {
color: green;
}
h2 {
font-family: Impact;
}
body {
text-align: center;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >DOM characterSet Property</ h2 >
< p >For returning the characterSet of the current URL,
click on the button: </ p >
< button onclick = "myFunction()" >Try it</ button >
< p id = "demo" ></ p >
< script >
function myFunction() {
var x = document.characterSet;
document.getElementById("demo").innerHTML = x;
}
</ script >
</ body >
</ html >
|
Output:

After clicking on the button:

Supported Browsers:
- Google Chrome 1.0
- Edge 12.0
- Internet Explorer 9.0
- Firefox 1.0
- Opera 12.1
- Safari 3.0
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
13 Jun, 2023
Like Article
Save Article