Jelajahi Sumber

【修复,渲染】解决图片点击打开功能失效问题

修复了自 e043dc9 引入的图片打开 bug,在点击事件委托中添加了对图片和 SVG 元素的点击处理逻辑,确保点击图片能够正确在新窗口打开图片链接。
PJ568 11 bulan lalu
induk
melakukan
8752dca1fb
1 mengubah file dengan 17 tambahan dan 1 penghapusan
  1. 17 1
      index.html

+ 17 - 1
index.html

@@ -2,7 +2,7 @@
 
 <html>
   <markdown-html
-    version="1.20.5"
+    version="1.20.6"
     author="PJ568"
     repo="https://github.com/PJ-568/markdown.html"
     license="CC BY-SA 4.0 International"
@@ -795,6 +795,22 @@
         );
         //// 点击事件委托
         document.addEventListener("click", function (event) {
+          const imgOrSvg = event.target.closest(".content img, .content svg");
+          if (imgOrSvg) {
+            const url =
+              imgOrSvg.getAttribute("src") ||
+              imgOrSvg.getAttribute("xlink:href");
+            if (url) {
+              window.open(url, "_blank");
+              event.preventDefault();
+            } else {
+              const newWindow = window.open("", "_blank");
+              newWindow.document.write(imgOrSvg.outerHTML);
+              newWindow.document.close();
+              event.preventDefault();
+            }
+            return;
+          }
           if (event.target.closest(".back-btn")) {
             window.history.back();
           } else if (event.target.closest(".refresh-btn")) {