Просмотр исходного кода

【新增】优化不支持 pushState 的浏览器

PJ568 2 лет назад
Родитель
Сommit
0d0c338e1c
1 измененных файлов с 7 добавлено и 5 удалено
  1. 7 5
      index.html

+ 7 - 5
index.html

@@ -3,7 +3,7 @@
 <!-- 作者:PJ568 -->
 <!-- 项目地址:https://github.com/PJ-568/markdown.html/ -->
 <!-- 本项目遵循 CC BY-SA 4.0 International 许可协议 -->
-<!-- v 0.3.1 -->
+<!-- v 0.4.0 -->
 
 <head>
   <meta charset="utf-8">
@@ -257,10 +257,12 @@
           const link = event.target.closest('a[href$=".md"]');
           if (link) {
             try {
-              event.preventDefault();
-              startLoad();
-              showMarkdown(decodePath(link.href));
-              history.pushState({ url: link.href, title: document.title, uid: link.href }, null, link.href);
+              if (history && history.pushState) {
+                event.preventDefault();
+                startLoad();
+                showMarkdown(decodePath(link.href));
+                history.pushState({ url: link.href, title: document.title, uid: link.href }, null, link.href);
+              }
             } catch (e) {
               console.error('自定义 Pjax 出错:' + e);
             }