mirror of
https://github.com/Ad-closeNN/blog-fuwari.git
synced 2026-05-31 01:20:06 -04:00
fix(script): 修复从其他页面切入时,关于页无法正确获取主机名的问题
This commit is contained in:
@@ -115,6 +115,7 @@ the error log is like driving with your eyes closed.
|
||||
- <a href="/assets/carbon-config.json" target="_blank">/public/assets/carbon-config.json</a> :[Carbon 官网](https://carbon.now.sh) 配置文件。
|
||||
|
||||
<script>
|
||||
function getHostname(){
|
||||
// 主机名解析
|
||||
const hostname = window.location.hostname;
|
||||
const siteType = document.getElementById('cdns');
|
||||
@@ -181,4 +182,11 @@ the error log is like driving with your eyes closed.
|
||||
else {
|
||||
hName.textContent = "本地 HTML 文件";
|
||||
}
|
||||
}
|
||||
|
||||
// 兼容 Astro 的客户端导航与首次加载
|
||||
document.addEventListener('astro:page-load', getHostname);
|
||||
document.addEventListener('astro:after-swap', getHostname);
|
||||
if (document.readyState !== 'loading') getHostname();
|
||||
document.addEventListener('DOMContentLoaded', getHostname);
|
||||
</script>
|
||||
Reference in New Issue
Block a user