随着乔布斯的回归,ipad2的发布,看来移动端的开发话题越来越火热了。在此列出一些能够在ios的最大竞争者——安卓(android)系统的检测方法。
JavaScript判断方法
搜索user agent字符串中的Android单词是最省事儿的方法:
<OL class=dp-c><LI class=alt><SPAN><SPAN class=keyword>if</SPAN><SPAN>(navigator.userAgent.match(/Android/i)) { </SPAN></SPAN><LI><SPAN> </SPAN><SPAN class=comment>// Do something! </SPAN><SPAN> </SPAN><LI class=alt><SPAN> </SPAN><SPAN class=comment>// Redirect to Android-site? </SPAN><SPAN> </SPAN><LI><SPAN> window.location = </SPAN><SPAN class=string>'http://android.davidwalsh.name'</SPAN><SPAN>; </SPAN><LI class=alt><SPAN> } </SPAN></LI></OL>PHP判断方法
同样,我们可以在PHP中使用strstr方法搜索user agent中是否有Android:
立即学习“PHP免费学习笔记(深入)”;
<OL class=dp-c><LI class=alt><SPAN><SPAN class=keyword>if</SPAN><SPAN>(</SPAN><SPAN class=func>strstr</SPAN><SPAN>(</SPAN><SPAN class=vars>$_SERVER</SPAN><SPAN>[</SPAN><SPAN class=string>'HTTP_USER_AGENT'</SPAN><SPAN>],</SPAN><SPAN class=string>'Android'</SPAN><SPAN>)) { </SPAN></SPAN><LI><SPAN> header(</SPAN><SPAN class=string>'Location: http://android.davidwalsh.name'</SPAN><SPAN>); </SPAN><LI class=alt><SPAN> </SPAN><SPAN class=func>exit</SPAN><SPAN>(); </SPAN><LI><SPAN> } </SPAN></LI></OL>另外,可以通过.htaccess来判断
我们可以使用.htaccess来判断和响应安卓设备!
<OL class=dp-xml><LI class=alt><SPAN><SPAN>RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$ </SPAN></SPAN><LI><SPAN> RewriteRule ^(.*)$ http://android.davidwalsh.name [</SPAN><SPAN class=attribute>R</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>301</SPAN><SPAN>] </SPAN></LI></OL>这样你就掌握了全部三种安卓设备的检测方法。
http://article.yeeyan.org/view/56089/176760
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号