ifApp.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. export const openApp = (url, callback) => {
  2. window.location.href = url
  3. var _clickTime = +new Date()
  4. function check(elsTime) {
  5. if (elsTime > 3000 || document.hidden || document.webkitHidden) {} else {
  6. callback && callback()
  7. }
  8. }
  9. //启动间隔20ms运行的定时器,并检测累计消耗时间是否超过3000ms,超过则结束
  10. var _count = 0,
  11. intHandle
  12. intHandle = setInterval(function() {
  13. _count++
  14. var elsTime = +new Date() - _clickTime
  15. if (_count >= 100 || elsTime > 3000) {
  16. clearInterval(intHandle)
  17. check(elsTime)
  18. }
  19. }, 20)
  20. }
  21. // 去下载
  22. export const goConfirmAddr = (url) => {
  23. // 是否是安卓QQ打开
  24. if (isIosPad) {
  25. window.location = url
  26. } else if (isAndroidPad) {
  27. window.location =url
  28. } else if (isIos) {
  29. window.location = url
  30. } else {
  31. window.location = url
  32. }
  33. }
  34. export const browser = {
  35. versions: function() {
  36. let u = navigator.userAgent;
  37. let app = navigator.appVersion;
  38. return {
  39. trident: u.indexOf('Trident') > -1, //IE内核
  40. presto: u.indexOf('Presto') > -1, //opera内核
  41. webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
  42. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
  43. mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
  44. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  45. android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 || u.indexOf('Linux') > -1, //android终端
  46. iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
  47. iPad: u.indexOf('iPad') > -1, //是否iPad
  48. webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
  49. weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
  50. qq: u.match(/\sQQ/i) == " qq", //是否QQ
  51. browser: navigator.userAgent.indexOf('MQQBrowser') > -1
  52. };
  53. }(),
  54. language: (navigator.browserLanguage || navigator.language).toLowerCase()
  55. }