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","" />
2951浏覽量

手機訪問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");//

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

聯系我(wǒ)們

一(yī)次需求提交或許正是成就一(yī)個出色産品的開(kāi)始。
歡迎填寫表格或發送合作郵件至: qczsky@126.com

大(dà)理青橙科技

電(diàn)話(huà):13988578755 13988578755

郵箱:qczsky@126.com

地址:大(dà)理市下(xià)關龍都春天10層