check_mobile.js 654 B

1234567891011121314151617181920
  1. var os = fBrowser()
  2. var origin = window.location.origin;
  3. const _pathname = window.location.pathname.split("/mobile.html")[0]
  4. // 如果不是pc 并且不是平板 并且是pc的地址 跳转到mobile
  5. if (os == 'pc') {
  6. window.location.href = origin + _pathname
  7. }
  8. //判断是pc还是移动
  9. function fBrowser() {
  10. var sUserAgent = navigator.userAgent.toLowerCase();
  11. if ((sUserAgent.match(/(iphone|ipod|android|ios|ipad|backerry|webos|symbian|windows phone|phone|mobile|webos|incognito|webmate|bada|nokia|lg|ucweb|skyfire)/i))) {
  12. //手机访问
  13. return "mobile";
  14. } else {
  15. //电脑访问
  16. return "pc";
  17. }
  18. }