Skip to content

Commit 729399c

Browse files
committed
【修复】优化页面内外跳转
- 更新版本号至 1.15.2 - 优化页面内跳转链接格式,与 window.location.search 保持一致 - 移除平滑滚动功能,简化代码结构 - 优化外部链接跳转逻辑,增加对特殊字符链接的支持
1 parent ce5ec03 commit 729399c

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

index.html

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22

33
<html>
4-
<markdown-html version="1.15.1" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
4+
<markdown-html version="1.15.2" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
55
license="CC BY-SA 4.0 International"></markdown-html>
66

77
<head>
@@ -460,7 +460,7 @@
460460
}
461461
linkHref = new URL(linkHref, 'http://example.com').pathname;
462462
}
463-
const newLink = `[${linkText}](${window.location.pathname}?p=${linkHref})`;
463+
const newLink = `[${linkText}](?p=${linkHref})`; // 链接格式与 window.location.search 一致
464464
markdown_content = markdown_content.replace(link, newLink);
465465
});
466466
}
@@ -600,29 +600,30 @@
600600
}
601601
return;
602602
}
603-
if (event.target.closest('nav .back-btn')) {
603+
if (event.target.closest('.back-btn')) {
604604
window.history.back();
605-
} else if (event.target.closest('nav .refresh-btn')) {
605+
} else if (event.target.closest('.refresh-btn')) {
606606
window.location.reload();
607-
} else if (event.target.closest('nav .dark-btn')) {
607+
} else if (event.target.closest('.dark-btn')) {
608608
darkmode.toggle();
609-
} else if (event.target.closest('nav .translate-switch')) {
609+
} else if (event.target.closest('.translate-switch')) {
610610
translate.changeLanguage(translate.language.getLocal());
611-
} else if (event.target.closest('.content a[href^="#"]')) {
612-
// 目录平滑移动
613-
const href = event.target.getAttribute('href');
614-
if (href !== '#') {
615-
event.preventDefault();
616-
const targetElement = document.querySelector(href);
617-
if (targetElement) {
618-
targetElement.scrollIntoView({
619-
behavior: 'smooth'
620-
});
621-
} else {
622-
console.error(`ID 为 ${targetId} 的元素不存在。`);
623-
}
624-
}
625-
} else if (event.target.closest('.content a:not([href$=".md"])')) {
611+
// 跳转。禁用原因是有些带有特殊字符的链接会出错或无法跳转
612+
// } else if (event.target.closest('.content a[href^="#"]')) {
613+
// // 目录平滑移动
614+
// const href = event.target.getAttribute('href');
615+
// if (href !== '#') {
616+
// event.preventDefault();
617+
// const targetElement = document.querySelector(href);
618+
// if (targetElement) {
619+
// targetElement.scrollIntoView({
620+
// behavior: 'smooth'
621+
// });
622+
// } else {
623+
// console.error(`ID 为 ${targetId} 的元素不存在。`);
624+
// }
625+
// }
626+
} else if (event.target.closest('.content a:not([href^="?"]):not([href^="#"]):not([href^="javascript:"])')) {
626627
const link = event.target.closest('a');
627628
if (link && link.href) {
628629
window.open(link.href, '_blank');

0 commit comments

Comments
 (0)