{"id":1024,"date":"2023-03-12T09:34:40","date_gmt":"2023-03-12T01:34:40","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1024"},"modified":"2023-04-29T13:13:56","modified_gmt":"2023-04-29T05:13:56","slug":"h5-judge-whether-the-browser-is-wechat-or-alipay","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/h5-judge-whether-the-browser-is-wechat-or-alipay\/","title":{"rendered":"H5\u5224\u65ad\u6d4f\u89c8\u5668\u662f\u5fae\u4fe1\u8fd8\u662f\u652f\u4ed8\u5b9d"},"content":{"rendered":"<p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u533a\u5206H5\u9875\u9762\u662f\u5728\u5fae\u4fe1\u4e2d\u6253\u5f00\u7684\u8fd8\u662f\u5728\u652f\u4ed8\u5b9d\u4e2d\u6253\u5f00\u7684\uff0c\u7136\u540e\u8fdb\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u8fd9\u5c31\u7528\u5230\u6d4f\u89c8\u5668\u5bf9\u8c61\u6a21\u578b\u4e2d\u7684Navigator \u5bf9\u8c61\uff0cNavigator \u5bf9\u8c61\u5305\u542b\u6709\u5173\u6d4f\u89c8\u5668\u7684\u4fe1\u606f\u3002\u6211\u4eec\u901a\u8fc7Navigator \u83b7\u53d6\u5230userAgent\u7684\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n<h2>\u516c\u5171\u65b9\u6cd5\u5c01\u88c5<\/h2>\n<p><!-- more --><\/p>\n<pre><code class=\"language-javascript\">function isAlipayOrWechat() {\n  var userAgent = navigator.userAgent.toLowerCase();\n  if (userAgent.match(\/Alipay\/i) === &quot;alipay&quot;) {\n    return &quot;alipay&quot;;\n    \/\/alert(&quot;\u652f\u4ed8\u5b9d\u6d4f\u89c8\u5668&quot;);\n  } else if (userAgent.match(\/MicroMessenger\/i) === &quot;micromessenger&quot;) {\n    return &quot;wechat&quot;;\n    \/\/alert(&quot;\u5fae\u4fe1\u6d4f\u89c8\u5668&quot;);\n  } else {\n    return &quot;&quot;;\n  }\n}\n\nexport { isAlipayOrWechat };<\/code><\/pre>\n<h2>Vue\u7ec4\u4ef6\u8c03\u7528<\/h2>\n<pre><code class=\"language-javascript\">&lt;template&gt;\n\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport { isAlipayOrWechat } from &quot;..\/assets\/js\/common&quot;;\nexport default {\n  data() {\n    return {\n      home: &quot;http:\/\/www.appblog.cn&quot;\n    };\n  },\n  created() {\n    var client = isAlipayOrWechat();\n    console.log(&quot;client: &quot; + client);\n\n  }\n};\n&lt;\/script&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u533a\u5206H5\u9875\u9762\u662f\u5728\u5fae\u4fe1\u4e2d\u6253\u5f00\u7684\u8fd8\u662f\u5728\u652f\u4ed8\u5b9d\u4e2d\u6253\u5f00\u7684\uff0c\u7136\u540e\u8fdb\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u8fd9\u5c31\u7528\u5230\u6d4f\u89c8\u5668\u5bf9\u8c61\u6a21\u578b\u4e2d\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[159],"class_list":["post-1024","post","type-post","status-publish","format-standard","hentry","category-frontend-basic","tag-h5"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1024"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1024\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}