rizzle

一个手机端网站的项目,考虑到用户可能用微信扫码打开网站,而微信内置浏览器并不允许用户进行下载。查阅资料后,我做了如下的兼容。

了解到可以用如下方法判断微信浏览器

function is_weixin(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
     } else {
        return false;
    }
}

(以上代码来自http://blog.wpjam.com/m/is_weixin/)

首先,下载链接改为一个新的html页面。在此新页面中改写上面的代码为

window.onload=function () {
    var ua = navigator.userAgent.toLowerCase();
    console.log(ua);
    if(ua.match(/MicroMessenger/i)!="micromessenger") {
            window.location="lesson.doc";
     }
}  

问题解决。so easy。

 

第一篇博客,low就low吧

分类:

技术点:

相关文章:

  • 2021-11-14
  • 2021-10-21
  • 2021-10-31
  • 2021-11-28
  • 2021-12-20
  • 2022-01-16
猜你喜欢
  • 2021-11-28
  • 2021-11-24
  • 2021-11-04
  • 2021-11-21
  • 2021-05-16
  • 2022-01-02
  • 2021-12-13
相关资源
相似解决方案