Document.characterSet

A propriedade somente leitura Document.characterSet retorna a character encoding(codificação de caracteres) do documento com o qual ele é renderizado atualmente. (Uma codificação de caracteres é um conjunto de caracteres e como interpretar bytes nesses caracteres.)

Um “character set”(conjunto de caracteres) e “character encoding”(codificação de caracteres) estão relacionados, mas diferentes. Apesar do nome dessa propriedade, ela retorna a codificação.

Usuários podem sobrepor a codificação especificada pelo desenvolvedor dentro do cabeçalho Content-Type (tipo de conteúdo) ou embutida como <meta charset = "utf-8">, como no menu Exibir → Codificacao de Texto Essa substituição é fornecida para corrigir codificações especificadas pelo desenvolvedor incorretas que resultam em texto ilegivel.

As propriedades document.charset e document.inputEncoding são aliases legados para document.characterSet. Não use mais eles.

Sintaxe

var string = document.characterSet;

Exemplos

<button onclick="console.log(document.characterSet);">
  Registro de Codificacao de Caracteres
</button>
<!-- mostra a codificacao de caracteres do documento no console do desevolvedor, como "ISO-8859-1" ou "UTF-8" -->

Especificações

Specification Status Comment
DOM
The definition of 'characterSet' in that specification.
Padrão em tempo real

Definição Inicial.

Compatibilidade do navegador

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
characterSetChrome Full support 1
Full support 1
Full support 1
Notes Alternate Name
Notes charset alias was made read-only in Chrome 45.
Alternate Name Uses the non-standard name: charset
Full support 1
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Edge Full support ≤79
Full support ≤79
Full support ≤79
Alternate Name
Alternate Name Uses the non-standard name: charset
Full support ≤79
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Firefox Full support Yes
Full support Yes
Full support 44
Alternate Name
Alternate Name Uses the non-standard name: charset
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
IE ?
?
?
Alternate Name
Alternate Name Uses the non-standard name: charset
?
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Opera Full support Yes
Full support Yes
?
Alternate Name
Alternate Name Uses the non-standard name: charset
?
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Safari Full support Yes
Full support Yes
Full support 9
Alternate Name
Alternate Name Uses the non-standard name: charset
?
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
WebView Android Full support 45
Full support 45
Full support Yes
Notes Alternate Name
Notes charset alias was made read-only in WebView 45.
Alternate Name Uses the non-standard name: charset
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Chrome Android Full support 45
Full support 45
Full support Yes
Notes Alternate Name
Notes charset alias was made read-only in Chrome 45.
Alternate Name Uses the non-standard name: charset
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Firefox Android Full support Yes
Full support Yes
Full support 44
Alternate Name
Alternate Name Uses the non-standard name: charset
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Opera Android Full support Yes
Full support Yes
?
Alternate Name
Alternate Name Uses the non-standard name: charset
?
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Safari iOS Full support Yes
Full support Yes
?
Alternate Name
Alternate Name Uses the non-standard name: charset
?
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding
Samsung Internet Android Full support 5.0
Full support 5.0
Full support Yes
Notes Alternate Name
Notes charset alias was made read-only in Samsung Internet 5.0.
Alternate Name Uses the non-standard name: charset
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: inputEncoding

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.
Uses a non-standard name.
Uses a non-standard name.