Skip to content

Instantly share code, notes, and snippets.

@xiaoshude
Forked from loo2k/wechat-browser-detect.js
Created November 20, 2017 02:41
Show Gist options
  • Save xiaoshude/6330da83146614cb9fd2cc1ef2270281 to your computer and use it in GitHub Desktop.
Save xiaoshude/6330da83146614cb9fd2cc1ef2270281 to your computer and use it in GitHub Desktop.
JavaScript 判断是否微信内置浏览器
var isWeixin = false;
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; });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment