<?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>孙立文的博客 &#187; Javascript</title>
	<atom:link href="http://sunliwen.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://sunliwen.com</link>
	<description>Never lose my passion!</description>
	<lastBuildDate>Sat, 21 Jan 2012 05:16:52 +0000</lastBuildDate>
	<language>zh</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>如何检测浏览器和操作系统的信息</title>
		<link>http://sunliwen.com/2011/11/detect-useragent/</link>
		<comments>http://sunliwen.com/2011/11/detect-useragent/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 19:17:53 +0000</pubDate>
		<dc:creator>Liwen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://sunliwen.com/?p=1664</guid>
		<description><![CDATA[在实现一个功能时，需从UserAgent中抽取出浏览器和操作系统的信息。 浏览器： Opera Chrome Internet Explorer Safari Firefox 操作系统： Windows iPad iPhone Android Mac OS X Linux 实现方法如下： function getBrowser&#40;&#41; &#123; var agent = navigator.userAgent; return window.opera ? &#34;Opera&#34; : /chrom/i.test&#40;agent&#41; ? &#34;Chrome&#34; : /msie/i.test&#40;agent&#41; ? &#34;Internet Explorer&#34; : /applewebkit/i.test&#40;navigator.appVersion&#41; ? &#34;Safari&#34; : /mozilla/i.test&#40;agent&#41; &#38;&#38; !/compatible&#124;webkit/i.test&#40;agent&#41; ? &#34;Firefox&#34; : &#34;&#34;; &#125; &#160; function getOS&#40;&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>在实现一个功能时，需从UserAgent中抽取出浏览器和操作系统的信息。</p>
<p>浏览器：</p>
<ul>
<li>Opera</li>
<li>Chrome</li>
<li>Internet Explorer</li>
<li>Safari</li>
<li>Firefox</li>
</ul>
<p>操作系统：</p>
<ul>
<li>Windows</li>
<li>iPad</li>
<li>iPhone</li>
<li>Android</li>
<li>Mac OS X</li>
<li>Linux</li>
</ul>
<p>实现方法如下：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getBrowser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> agent <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">userAgent</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> window.<span style="color: #660066;">opera</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Opera&quot;</span>
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/chrom/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Chrome&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/msie/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Internet Explorer&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/applewebkit/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">appVersion</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Safari&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/mozilla/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!/</span>compatible<span style="color: #339933;">|</span>webkit<span style="color: #339933;">/</span>i.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Firefox&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> getOS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> agent <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">userAgent</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009966; font-style: italic;">/windows/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Windows&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/ipad/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;iPad&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/iphone/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;iPhone&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/android/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Android&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/mac/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Mac OS X&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/x11/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009966; font-style: italic;">/linux/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>agent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;Linux&quot;</span> 
        <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>需要注意的是，检测顺序敏感。</p>
<p>参考：<br />
* <a href="http://www.quirksmode.org/js/detect.html">Browser detect</a><br />
* <a href="http://detectmobilebrowsers.com/">Detect Mobile Browsers</a></p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="ckepop">
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_douban"></a>
	<a class="jiathis_button_instapaper"></a>
	<a class="jiathis_button_stubleupon"></a>
	<a href="http://www.jiathis.com/share?uid=1544311" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">var jiathis_config = {data_track_clickback:true};</script>
<script type="text/javascript" src="http://v2.jiathis.com/code_mini/jia.js?uid=1544311" charset="utf-8"></script>
<!-- JiaThis Button END --></div><hr />
<p>
<small>
Tags: <a href="http://sunliwen.com/tag/javascript/" rel="tag">Javascript</a><br/>
<a href="http://sunliwen.com/2011/11/detect-useragent/#comments-heading">没有评论</a>
</small>
</p>]]></content:encoded>
			<wfw:commentRss>http://sunliwen.com/2011/11/detect-useragent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分析PrototypeJS</title>
		<link>http://sunliwen.com/2006/01/prototype-js/</link>
		<comments>http://sunliwen.com/2006/01/prototype-js/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 03:57:59 +0000</pubDate>
		<dc:creator>Liwen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://fishpot.spaces.live.com/Blog/cns!AA7DB611C0406AB4!278.entry</guid>
		<description><![CDATA[比较优秀的两个PrototypeJS注解 http://www.sergiopereira.com/articles/prototype.js.html https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html Tags: Javascript 没有评论]]></description>
			<content:encoded><![CDATA[<p>比较优秀的两个PrototypeJS注解</p>
<div><a href="http://www.sergiopereira.com/articles/prototype.js.html">http://www.sergiopereira.com/articles/prototype.js.html</a></div>
<div><a href="https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html">https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html</a></div>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="ckepop">
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_douban"></a>
	<a class="jiathis_button_instapaper"></a>
	<a class="jiathis_button_stubleupon"></a>
	<a href="http://www.jiathis.com/share?uid=1544311" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">var jiathis_config = {data_track_clickback:true};</script>
<script type="text/javascript" src="http://v2.jiathis.com/code_mini/jia.js?uid=1544311" charset="utf-8"></script>
<!-- JiaThis Button END --></div><hr />
<p>
<small>
Tags: <a href="http://sunliwen.com/tag/javascript/" rel="tag">Javascript</a><br/>
<a href="http://sunliwen.com/2006/01/prototype-js/#comments-heading">没有评论</a>
</small>
</p>]]></content:encoded>
			<wfw:commentRss>http://sunliwen.com/2006/01/prototype-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

