多了就不说了,直接上代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
 
<span style="color: #003366;font-weight: bold">function</span> checkIsIphoneIpad<span style="color: #009900">(</span><span style="color: #009900">)</span>
<span style="color: #009900">{</span>
	<span style="color: #003366;font-weight: bold">var</span> pda_user_agent_list <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">new</span> Array<span style="color: #009900">(</span><span style="color: #3366CC">"iPhone"</span><span style="color: #339933">,</span> <span style="color: #3366CC">"iPod"</span><span style="color: #339933">,</span> <span style="color: #3366CC">"iPad"</span><span style="color: #006600;font-style: italic">/*, "GTB"*/</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
	<span style="color: #003366;font-weight: bold">var</span> pda_app_name_list <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">new</span> Array<span style="color: #009900">(</span><span style="color: #3366CC">"Microsoft Pocket Internet Explorer"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #006600;font-style: italic">//来自www.chhua.com</span>
	<span style="color: #003366;font-weight: bold">var</span> user_agent <span style="color: #339933">=</span> navigator.<span style="color: #660066">userAgent</span>.<span style="color: #660066">toString</span><span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
	<span style="color: #000066;font-weight: bold">for</span> <span style="color: #009900">(</span><span style="color: #003366;font-weight: bold">var</span> i<span style="color: #339933">=</span><span style="color: #CC0000">0</span><span style="color: #339933">;</span> i<span style="color: #339933"><</span>pda_user_agent_list.<span style="color: #660066">length</span><span style="color: #339933">;</span> i<span style="color: #339933">++</span><span style="color: #009900">)</span> <span style="color: #009900">{</span>
		<span style="color: #000066;font-weight: bold">if</span> <span style="color: #009900">(</span>user_agent.<span style="color: #660066">indexOf</span><span style="color: #009900">(</span>pda_user_agent_list<span style="color: #009900">[</span>i<span style="color: #009900">]</span><span style="color: #009900">)</span> <span style="color: #339933">>=</span> <span style="color: #CC0000">0</span><span style="color: #009900">)</span> <span style="color: #009900">{</span>
			<span style="color: #000066;font-weight: bold">return</span> <span style="color: #003366;font-weight: bold">true</span><span style="color: #339933">;</span>
		<span style="color: #009900">}</span>
	<span style="color: #009900">}</span>
	<span style="color: #003366;font-weight: bold">var</span> appName <span style="color: #339933">=</span> navigator.<span style="color: #660066">appName</span>.<span style="color: #660066">toString</span><span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
	<span style="color: #000066;font-weight: bold">for</span> <span style="color: #009900">(</span><span style="color: #003366;font-weight: bold">var</span> i<span style="color: #339933">=</span><span style="color: #CC0000">0</span><span style="color: #339933">;</span> i<span style="color: #339933"><</span>pda_app_name_list.<span style="color: #660066">length</span><span style="color: #339933">;</span> i<span style="color: #339933">++</span><span style="color: #009900">)</span> <span style="color: #009900">{</span>
		<span style="color: #000066;font-weight: bold">if</span> <span style="color: #009900">(</span>user_agent.<span style="color: #660066">indexOf</span><span style="color: #009900">(</span>pda_app_name_list<span style="color: #009900">[</span>i<span style="color: #009900">]</span><span style="color: #009900">)</span> <span style="color: #339933">>=</span> <span style="color: #CC0000">0</span><span style="color: #009900">)</span> <span style="color: #009900">{</span>
			<span style="color: #000066;font-weight: bold">return</span> <span style="color: #003366;font-weight: bold">true</span><span style="color: #339933">;</span>
		<span style="color: #009900">}</span>
	<span style="color: #009900">}</span>
 
	<span style="color: #000066;font-weight: bold">return</span> <span style="color: #003366;font-weight: bold">false</span><span style="color: #339933">;</span>
<span style="color: #009900">}</span>