独角兽企业重金招聘Python工程师标准>>>
js判断是否是微信浏览器
functionis_weixin(){varua=window.navigator.userAgent.toLowerCase();if(ua.match(/MicroMessenger/i)=='micromessenger'){$("#rs").text("微信浏览器");}else{$("#rs").text("不是微信浏览器");}}
PHP判断是否是微信浏览器
$is_weixin=(is_weixin()==true)?"微信浏览器":"不是微信浏览器";
functionis_weixin(){if(strpos($_SERVER['HTTP_USER_AGENT'],'MicroMessenger')!==false){returntrue;}returnfalse;}
PHP判断手机还是电脑
<?php$is_mobile=(is_mobile()==true)?"手机":"电脑";echo'<label>php判断结果:</label><spanclass="red">'.$is_mobile.'</span>';?>
functionis_mobile(){$user_agent=$_SERVER['HTTP_USER_AGENT'];$mobile_agents=array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","iphone","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wigbrowser","wii","windowsce","wireless","xda","xde","zte");$is_mobile=false;foreach($mobile_agentsas$device){if(stristr($user_agent,$device)){$is_mobile=true;break;}}return$is_mobile;}
JS判断手机还是电脑
<p><label>js判断结果:</label><spanid="rs_js"class="red"></span></p>
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent)||/Android/i.test(navigator.userAgent)||/BlackBerry/i.test(navigator.userAgent)||/IEMobile/i.test(navigator.userAgent)||(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(/iPad/i.test(navigator.userAgent)){$("#rs_js").text("iPad平板");}else{$("#rs_js").text("手机");}}else{$("#rs_js").text("电脑");}