Home  >  Article  >  Web Front-end  >  HTML5 actual combat and analysis of character set attributes (charset and defaultCharset)

HTML5 actual combat and analysis of character set attributes (charset and defaultCharset)

黄舟
黄舟Original
2017-02-11 11:25:352560browse

HTML5 has also updated the character set attributes, among which the charset and defaultCharset attributes are the newly added character set attributes in HTML5. The detailed explanation of the charset and defaultCharset attributes can be found in HTML5 Practical Combat and Analysis of Character Set Attributes. Let’s learn about them together below.


The charset attribute of HTML5 actual combat and analysis of the character set attribute


The charset attribute in HTML5 represents the document medieval The character set used, can also be used to specify a new character set. By default, the value of the charset attribute is "UTF-16", but it can be modified through the meta tag, response header, or directly setting the charset attribute. A small example is as follows:


JavaScript code



##

alert(document.charset) // 谷歌下测试  "UTF-8"
document.charset = "UTF-16"
alert(document.charset) // 谷歌下测试 "UTF-16LE"



The defaultCharset attribute of the character set attribute of HTML5 actual combat and analysis


## The defaultCharset attribute represents the default browser and operating system Settings, what should be the default character set of the current document. If the document does not have a default character set, the values ​​of the charset attribute and the defaultCharset attribute may be different. A small example is as follows:


JavaScript code


##
if(document.charset != document.defaultCharset){
	alert("编码不一样哟")
}



With the charset attribute and defaultCharset attribute, we can get specific information about the character encoding used in the document, and can also reasonably control the character encoding. When this works properly, it can ensure that users can view pages or use applications normally. Browsers that support the document.charset attribute include Safari, Chrome, IE, Firefox and Opera. Browsers that support the document.defaultCharset attribute are Chrome, IE and Safari.

The above is the content of the character set attributes (charset and defaultCharset) of HTML5 actual combat and analysis. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!




##

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn