Skip to content

Commit d9e9965

Browse files
committed
【修复,渲染】解决图片点击打开功能失效问题
修复了自 e043dc9 引入的图片打开 bug,在点击事件委托中添加了对图片和 SVG 元素的点击处理逻辑,确保点击图片能够正确在新窗口打开图片链接。
1 parent 1198051 commit d9e9965

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

index.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<html>
44
<markdown-html
5-
version="1.20.5"
5+
version="1.20.6"
66
author="PJ568"
77
repo="https://github.com/PJ-568/markdown.html"
88
license="CC BY-SA 4.0 International"
@@ -795,6 +795,22 @@
795795
);
796796
//// 点击事件委托
797797
document.addEventListener("click", function (event) {
798+
const imgOrSvg = event.target.closest(".content img, .content svg");
799+
if (imgOrSvg) {
800+
const url =
801+
imgOrSvg.getAttribute("src") ||
802+
imgOrSvg.getAttribute("xlink:href");
803+
if (url) {
804+
window.open(url, "_blank");
805+
event.preventDefault();
806+
} else {
807+
const newWindow = window.open("", "_blank");
808+
newWindow.document.write(imgOrSvg.outerHTML);
809+
newWindow.document.close();
810+
event.preventDefault();
811+
}
812+
return;
813+
}
798814
if (event.target.closest(".back-btn")) {
799815
window.history.back();
800816
} else if (event.target.closest(".refresh-btn")) {

0 commit comments

Comments
 (0)