Skip to content

Instantly share code, notes, and snippets.

@loo2k
Last active March 14, 2019 02:08
Show Gist options
  • Save loo2k/6769e0a69b5b99d051b3 to your computer and use it in GitHub Desktop.
Save loo2k/6769e0a69b5b99d051b3 to your computer and use it in GitHub Desktop.

Revisions

  1. loo2k revised this gist Jul 10, 2016. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions wechat-browser-detect.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    // 使用 userAgent 判断是否微信内置浏览器
    // 不推荐使用 用户可能会自行修改浏览器的 userAgent
    if( navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1 || typeof navgator.wxuserAgent !== "undefined" ) {
    return true;
    }
    var isWeixin = false;

    // 使用微信 JS 对象判断是否微信内置浏览器
    // 建议使用此方法进行判断
    if( typeof WeixinJSBridge !== "undefined" ) {
    return true;
    if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
    isWeixin = true;
    } else {
    if (document.addEventListener) {
    document.addEventListener("WeixinJSBridgeReady", function() { isWeixin = true; }, false);
    } else if (document.attachEvent) {
    document.attachEvent("WeixinJSBridgeReady", function() { isWeixin = true; });
    document.attachEvent("onWeixinJSBridgeReady", function() { isWeixin = true; });
    }
    }
  2. loo2k renamed this gist Oct 10, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. loo2k revised this gist Oct 10, 2014. No changes.
  4. loo2k created this gist Oct 10, 2014.
    11 changes: 11 additions & 0 deletions wechat-browser-detect
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // 使用 userAgent 判断是否微信内置浏览器
    // 不推荐使用 用户可能会自行修改浏览器的 userAgent
    if( navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1 || typeof navgator.wxuserAgent !== "undefined" ) {
    return true;
    }

    // 使用微信 JS 对象判断是否微信内置浏览器
    // 建议使用此方法进行判断
    if( typeof WeixinJSBridge !== "undefined" ) {
    return true;
    }