<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thinking for Fun &#187; HTML5</title>
	<atom:link href="http://jsfox.cn/blog/tag/html5/feed" rel="self" type="application/rss+xml" />
	<link>http://jsfox.cn/blog</link>
	<description>网络 ● 生活 ● 技术</description>
	<lastBuildDate>Tue, 01 Jun 2010 01:52:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Web文档编码的指定</title>
		<link>http://jsfox.cn/blog/learning/web-document-charset.html</link>
		<comments>http://jsfox.cn/blog/learning/web-document-charset.html#comments</comments>
		<pubDate>Fri, 28 May 2010 02:32:36 +0000</pubDate>
		<dc:creator>yongbin</dc:creator>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[编码]]></category>

		<guid isPermaLink="false">http://jsfox.cn/blog/?p=182</guid>
		<description><![CDATA[Web开发中，文档常常指：(X)HTML文档、XML文档、CSS文档、js文档。指定文档编码的方式有以下几种：
HTTP Header中指定文档编码
在一个典型的HTTP响应头里，Content-Type的值中可以指定文档编码，如：
HTTP/1.1 200 OK
Date        Tue, 11 May 2010 04:09:22 GMT
Server      Apache
Content-Type    text/html; charset=gb2312

对于动态网页，用这种方式指定文档编码，在脚本中直接输出响应头即可：
header( 'Content-type: text/html; charset=gb2312' );

对于静态网页、CSS文件等，则需要在Apache等服务器中配置，例如：
AddType 'text/html; charset=gb2312' html

Content-Type meta元素中指定HTML文档编码

对于HTML文档（或当成HTML解析的XHTML文档），用这种方式指定文档编码，应在&#60;head&#62;标签 里的最上方，加入：
&#60;meta http-equiv="Content-type" content="text/html; /&#62;

指定XML文档编码
对于XML文档，如果不指定编码，则一般会按照UTF-8来解析文档。指定编码的方式是在第一行加入：
&#60;?xml version="1.0" encoding="gb2312"?&#62;

HTML5的charset meta元素
我们潮一些，DOCTYPE为HTML5的文档，可以用带有meta标签的charset属性指定文档编码，类似于这 样：
&#60;meta charset="gb2312"&#62;

用链接的charset属性指定编码
&#60;a&#62;, &#60;link&#62;, &#60;script&#62;元素都可以带有charset属性，用来指定目标文档的编码。例如：
详见：&#60;a href="../index.html" charset="utf-8"&#62;老田的博客&#60;/a&#62;。

但一般html的文档都采用其他方式指定编码，所以此方法常用于指定外部script脚本的文档编码，例如：
&#60;script type="text/javascript" src="main.js" charset="gb2312"&#62;&#60;/script&#62;

使用@charset指定CSS文档编码
如果CSS文档中存在非ASCII字符，为了不让浏览器费力去猜测编码，可以指定CSS文档的编码。一种方式是使用 @charset指定，在CSS文件的第一行：
@charset "utf-8";

编码指定方式的优先级
上述方式指定文档编码，会使用下面的优先级：

 HTTP响应头的Content-Type
 [...]]]></description>
			<content:encoded><![CDATA[<p>Web开发中，文档常常指：(X)HTML文档、XML文档、CSS文档、js文档。指定文档编码的方式有以下几种：</p>
<h2>HTTP Header中指定文档编码</h2>
<p>在一个典型的HTTP响应头里，Content-Type的值中可以指定文档编码，如：</p>
<pre>HTTP/1.1 200 OK
Date        Tue, 11 May 2010 04:09:22 GMT
Server      Apache
Content-Type    text/html; charset=gb2312
</pre>
<p>对于动态网页，用这种方式指定文档编码，在脚本中直接输出响应头即可：</p>
<pre>header( 'Content-type: text/html; charset=gb2312' );
</pre>
<p>对于静态网页、CSS文件等，则需要在Apache等服务器中配置，例如：</p>
<pre>AddType 'text/html; charset=gb2312' html
</pre>
<h2>Content-Type meta元素中指定HTML文档编码</h2>
<p><span id="more-182"></span></p>
<p>对于HTML文档（或当成HTML解析的XHTML文档），用这种方式指定文档编码，应在&lt;head&gt;标签 里的最上方，加入：</p>
<pre>&lt;meta http-equiv="Content-type" content="text/html; /&gt;
</pre>
<h2>指定XML文档编码</h2>
<p>对于XML文档，如果不指定编码，则一般会按照UTF-8来解析文档。指定编码的方式是在第一行加入：</p>
<pre>&lt;?xml version="1.0" encoding="gb2312"?&gt;
</pre>
<h2>HTML5的charset meta元素</h2>
<p>我们潮一些，DOCTYPE为HTML5的文档，可以用带有meta标签的charset属性指定文档编码，类似于这 样：</p>
<pre>&lt;meta charset="gb2312"&gt;
</pre>
<h2>用链接的charset属性指定编码</h2>
<p>&lt;a&gt;, &lt;link&gt;, &lt;script&gt;元素都可以带有charset属性，用来指定目标文档的编码。例如：</p>
<pre>详见：&lt;a href="../index.html" charset="utf-8"&gt;老田的博客&lt;/a&gt;。
</pre>
<p>但一般html的文档都采用其他方式指定编码，所以此方法常用于指定外部script脚本的文档编码，例如：</p>
<pre>&lt;script type="text/javascript" src="main.js" charset="gb2312"&gt;&lt;/script&gt;
</pre>
<h2>使用@charset指定CSS文档编码</h2>
<p>如果CSS文档中存在非ASCII字符，为了不让浏览器费力去猜测编码，可以指定CSS文档的编码。一种方式是使用 @charset指定，在CSS文件的第一行：</p>
<pre>@charset "utf-8";
</pre>
<h2>编码指定方式的优先级</h2>
<p>上述方式指定文档编码，会使用下面的优先级：</p>
<ol>
<li> HTTP响应头的Content-Type</li>
<li> XML的首行声明</li>
<li> meta标签charset声明</li>
<li> 链接的charset属性</li>
</ol>
<p>例如对于一个CSS文件，它的编码优先级会按照下面的顺序指定：</p>
<ol>
<li> HTTP Content-Type</li>
<li> @charset rule</li>
<li> &lt;link charset=&#8221;..&#8221; rel=&#8221;stylesheet&#8221; … /&gt;</li>
</ol>
<h2>总结</h2>
<p>本文总结了Web文档（包括HTML, XHTML, XML, CSS, JS）的编码指定方式。比较常见的是(X)HTML文档中用meta标签指定编码，但优先级不如HTTP响应头高。外部js/css文件指定编码的方法也不尽相同，js文件用引用它的script tag charset attribute指定，css文件用文件开头的@charset指定。</p>
]]></content:encoded>
			<wfw:commentRss>http://jsfox.cn/blog/learning/web-document-charset.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML5 历史、现状及未来</title>
		<link>http://jsfox.cn/blog/others/html5-history-and-future.html</link>
		<comments>http://jsfox.cn/blog/others/html5-history-and-future.html#comments</comments>
		<pubDate>Tue, 20 Apr 2010 11:31:38 +0000</pubDate>
		<dc:creator>yongbin</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[IE8]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://jsfox.cn/blog/?p=179</guid>
		<description><![CDATA[分享一下HTML5的东西。
HTML5 历史、现状及未来
View more presentations from Yongbin Tian.


]]></description>
			<content:encoded><![CDATA[<p>分享一下HTML5的东西。</p>
<div id="__ss_3787971" style="width: 425px;"><strong><a title="HTML5 历史、现状及未来" href="http://www.slideshare.net/duckuu/html5-3787971">HTML5 历史、现状及未来</a></strong><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=html5-100420061434-phpapp01&amp;stripped_title=html5-3787971" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=html5-100420061434-phpapp01&amp;stripped_title=html5-3787971" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/duckuu">Yongbin Tian</a>.</div>
<p><span id="more-179"></span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://jsfox.cn/blog/others/html5-history-and-future.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

