jumpurl.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function is_weixin() {
  2. var ua = navigator.userAgent.toLowerCase();
  3. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  4. return true;
  5. } else {
  6. return false;
  7. }
  8. }
  9. var isWeixin = is_weixin();
  10. var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight;
  11. function loadHtml() {
  12. var div = document.createElement('div');
  13. div.id = 'weixin-tip';
  14. div.innerHTML = '<p><img src="images/live_weixin.png" alt="微信打开"/></p>';
  15. document.body.appendChild(div);
  16. }
  17. function loadStyleText(cssText) {
  18. var style = document.createElement('style');
  19. style.rel = 'stylesheet';
  20. style.type = 'text/css';
  21. try {
  22. style.appendChild(document.createTextNode(cssText));
  23. } catch (e) {
  24. style.styleSheet.cssText = cssText; //ie9以下
  25. }
  26. var head = document.getElementsByTagName("head")[0]; //head标签之间加上style样式
  27. head.appendChild(style);
  28. }
  29. var cssText = "#weixin-tip{position: fixed; left:0; top:0; background: rgba(0,0,0,0.8); filter:alpha(opacity=80); width: 100%; height:100%; z-index: 100;} #weixin-tip p{text-align: center; margin-top: 10%; padding:0 5%;}";
  30. var browser = {
  31. versions: function () {
  32. var u = navigator.userAgent, app = navigator.appVersion;
  33. return { //移动终端浏览器版本信息
  34. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  35. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
  36. iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
  37. iPad: u.indexOf('iPad') > -1, //是否iPad
  38. };
  39. }(),
  40. }
  41. $('.btn').on('click', function(event) {
  42. var jumpurl = document.getElementById("jumpurl");
  43. if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios) {
  44. jumpurl.href = "https://itunes.apple.com/us/app/%E5%8D%97%E6%96%B9%E5%8C%BB%E5%8A%A1%E9%80%9A/id1205266027?l=zh&mt=8";
  45. }
  46. if (browser.versions.android) {
  47. if(isWeixin){
  48. loadHtml();
  49. loadStyleText(cssText);
  50. }
  51. jumpurl.href = "http://ycmz.dept.nfyy.com/nfywt_patient_latest.apk";
  52. }
  53. });