Quellcode durchsuchen

跳转微信小程序

hwb0 vor 3 Jahren
Ursprung
Commit
92a7b9320d
1 geänderte Dateien mit 35 neuen und 1 gelöschten Zeilen
  1. 35 1
      public/jump.html

+ 35 - 1
public/jump.html

@@ -6,6 +6,40 @@
   <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
 
   <script>
+    function docReady(fn) {
+        if (document.readyState === 'complete' || document.readyState === 'interactive') {
+          fn()
+        } else {
+          document.addEventListener('DOMContentLoaded', fn);
+        }
+      }
+
+      docReady(async function() {
+        var ua = navigator.userAgent.toLowerCase()
+        var isWXWork = ua.match(/wxwork/i) == 'wxwork'
+        var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
+        var isMobile = false
+        var isDesktop = false
+        if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
+          isMobile = true
+        } else {
+          isDesktop = true
+        }
+
+        var containerEl = document.getElementById('container')
+
+        if (isWeixin) {
+          console.log('111', 111)
+          containerEl.innerHTML = '微信'
+        } else if (isDesktop) {
+         console.log('222', 222)
+         containerEl.innerHTML = '电脑'
+        }  else {
+          console.log('333', 333)
+          containerEl.innerHTML = '其他'
+        }
+      })
+
     function ajax(options) {
       return new Promise((resolve, reject) => {
         if (!options.url) {
@@ -113,7 +147,7 @@
       <div class="skip-theme-txt">小程序</div>
     </div>
     <div class="skip-btn">
-      <p onclick="openWeapp()">打开微信小程序</p>
+      <p onclick="openWeapp()" id="container">打开微信小程序</p>
     </div>
   </div>
 </body>