function mobile_device_detect(url) { var thisOS=navigator.platform; var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","" />
2980浏览量

手机访问pc网站自动跳转手机端网站代码

来源: 时间:2013-12-18

如何让别人访问你的pc端的官网直接跳转到移动端的网站呢?


  1. LANGUAGE="JavaScript">
  2. function mobile_device_detect(url)
  3. {
  4. var thisOS=navigator.platform;
  5. var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
  6. for(var i=0;i<os.length;i++)
  7. {
  8. if(thisOS.match(os[i]))
  9. {
  10. window.location=url;
  11. }
  12. }
  13. //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
  14. if(navigator.platform.indexOf('iPad') != -1)
  15. {
  16. window.location=url;
  17. }
  18. //做这一部分是因为Android手机的内核也是Linux
  19. //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
  20. var check = navigator.appVersion;
  21. if( check.match(/linux/i) )
  22. {
  23. //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
  24. if(check.match(/mobile/i) || check.match(/X11/i))
  25. {
  26. window.location=url;
  27. }
  28. }
  29. //类in_array函数
  30. Array.prototype.in_array = function(e)
  31. {
  32. for(i=0;i<this.length;i++)
  33. {
  34. if(this[i] == e)
  35. return true;
  36. }
  37. return false;
  38. }
  39. }
  40. mobile_device_detect("http://***.***.com");
代码

备注说明:

这里的mobile_device_detect("http://***.***.com");//

(里面的地址填的就是您的移动端的网站地址)

联系我们

一次需求提交或许正是成就一个出色产品的开始。
欢迎填写表格或发送合作邮件至: qczsky@126.com

大理青橙科技

电话:13988578755 13988578755

邮箱:qczsky@126.com

地址:大理市下关龙都春天10层

如果您无法识别验证码,请点图片更换