為企業提供網站平臺解決方案

178 7892 1916

QQ客服:點擊這里給我發消息 點擊這里給我發消息

最新動態:

常見問題

你的位置:e球彩ef进球数 > 建站知識 > 常見問題 > js php 判斷手機電腦訪問跳轉

e球彩胜平负四场多少钱:js php 判斷手機電腦訪問跳轉

發布時間:2013-11-07 12:17作者:e球彩ef进球数網址:e球彩ef进球数瀏覽:次
在做電腦和手機版網站建設過中,經常遇到,根據訪問設備跳轉到不同的網站。下面桂林螞蟻網絡就教大家如何用js php等方法來實現電腦手機訪問跳頁面。 方法一:百度js script src=//siteapp.baidu.com/static/webappservice/uaredirect.js type=text/javascript/script script type=text/javascriptuaredire
在做電腦和手機版網站建設過中,經常遇到,根據訪問設備跳轉到不同的網站。下面桂林螞蟻網絡就教大家如何用js php等方法來實現電腦手機訪問跳頁面。
方法一:百度js
<script src="//siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("你的手機版網址");</script>

方法二:純js

<script type="text/javascript">    
  
    <!--    
  
    //平臺、設備和操作系統     
  
    var system ={    
  
        win : false,    
  
        mac : false,    
  
        xll : false    
  
    };    
  
    //檢測平臺     
  
    var p = navigator.platform;    
  
    //alert(p);    
  
    system.win = p.indexOf("Win") == 0;    
  
    system.mac = p.indexOf("Mac") == 0;    
  
    system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);    
  
    //跳轉語句     
  
    if(system.win||system.mac||system.xll){//轉向后臺登陸頁面    
  
        window.location.href="index.html";    
  
    }else{    
  
        window.location.href="m.html";    
  
    }    
  
    -->    
  
</script>
方法三:PHP
<?php 
header("Content-type:text/html;charset=utf-8"); 
function is_mobile(){ 
$user_agent = $_SERVER['HTTP_USER_AGENT']; 
$mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","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","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","wig browser","wii","windows ce","wireless","xda","xde","zte"); 
$is_mobile = false; 
foreach ($mobile_agents as $device) { 
if (stristr($user_agent, $device)) { 
$is_mobile = true; 
break; 
return $is_mobile; 
if(is_mobile()){ 
echo "手機"; 
}else{ 
echo "電腦";