فهرست منبع

修改离线包图标

wangfumin 2 هفته پیش
والد
کامیت
c78ba2ea12
1فایلهای تغییر یافته به همراه17 افزوده شده و 7 حذف شده
  1. 17 7
      offline.html

+ 17 - 7
offline.html

@@ -21,19 +21,29 @@
   <script>
     (function () {
       try {
-        var iconEl = document.getElementById('app-icon');
-        if (!iconEl) return;
-
-        var params = new URL(window.location.href).searchParams;
-        var fromRoute = (params.get('fromRoute') || '').toLowerCase();
+        var params = window.location.hash;
+        var query = params.indexOf('?') > -1 ? params.split('?')[1] : '';
+        var fromRoute = (new URLSearchParams(query).get('fromRoute') || '').toLowerCase();
         var iconMap = {
           criminal: '/criminal.ico',
           xmfire: '/jmlogo.png',
           cjzfire: '/logo_big.ico'
         };
-
         var href = iconMap[fromRoute] || '/favicon.ico';
-        iconEl.setAttribute('href', href);
+        // 查找现有的favicon链接元素
+        let link = document.querySelector("link[rel~='icon']");
+        if (link) {
+          // 如果存在,更新href属性
+          link.href = href;
+          console.log('更新favicon为', href);
+        } else {
+          // 如果不存在,创建新的favicon链接元素
+          link = document.createElement('link');
+          link.rel = 'icon';
+          link.type = 'image/ico';
+          link.href = href;
+          document.head.appendChild(link);
+        }
       } catch (e) {
         // 容错,不影响页面加载
       }