无需申请自动送彩金68_白菜送彩金网站大全[无需申请秒送彩金]
做最好的网站
来自 无需申请自动 2019-07-18 19:39 的文章
当前位置: 无需申请自动送彩金68 > 无需申请自动 > 正文

判断访客终端类型集锦,方法的使用详解

 该方法返回一个数字,表示给定索引处的字符的Unicode值。

当用户使用手机等移动终端访问网站时,我们可以通过程序检测用户终端类型,如果是手机用户,则引导用户访问适配手机屏幕的移动站点。本文将介绍分别使用PHP和JAVASCRIPT代码判断用户终端类型。

本文实例讲述了js html5获取用户地理位置信息并在Google地图上显示的方法。分享给大家供大家参考。具体实现方法如下:

Unicode码点范围为0到1114111。前128个Unicode码点的ASCII字符编码的直接匹配。charCodeAt()将始终返回一个值小于65,536。
语法

PHP版

<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your position:</p>
<button onclick="getLocation()">Try It</button>
<div id="mapholder"></div>
<script>
var x=document.getElementById("demo");
function getLocation()
 {
 if (navigator.geolocation)
  {
  navigator.geolocation.getCurrentPosition(showPosition,showError);
  }
 else{x.innerHTML="Geolocation is not supported by this browser.";}
 }
function showPosition(position)
 {
 var latlon=position.coords.latitude "," position.coords.longitude;
 var img_url="http://maps.googleapis.com/maps/api/staticmap?center="
  latlon "&zoom=14&size=400x300&sensor=false";
 document.getElementById("mapholder").innerHTML="<img src='" img_url "' />";
 }
function showError(error)
 {
 switch(error.code) 
  {
  case error.PERMISSION_DENIED:
   x.innerHTML="User denied the request for Geolocation."
   break;
  case error.POSITION_UNAVAILABLE:
   x.innerHTML="Location information is unavailable."
   break;
  case error.TIMEOUT:
   x.innerHTML="The request to get user location timed out."
   break;
  case error.UNKNOWN_ERROR:
   x.innerHTML="An unknown error occurred."
   break;
  }
 }
</script>
</body>
</html>
string.charCodeAt(index);

我们使用PHP的$_SERVER['HTTP_USER_AGENT']来获取手机用户浏览器的用户代理,然后匹配已有的各种手机浏览器代理库,如果含有匹配的关键字,则判断为手机(移动终端)用户。

希望本文所述对大家的web程序设计有所帮助。

下面是参数的详细信息:

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","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","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; 
} 

您可能感兴趣的文章:

  • Asp.net MVC利用knockoutjs实现登陆并记录用户的内外网IP及所在城市(推荐)
  • JavaScript获取用户所在城市及地理位置

本文由无需申请自动送彩金68发布于无需申请自动,转载请注明出处:判断访客终端类型集锦,方法的使用详解

关键词: