mirror of
http://junepve.top:3000/chicrobot/mainPage.git
synced 2026-10-30 04:31:29 +08:00
修改跳转为新窗口跳转
This commit is contained in:
1 parent
5b79e9e733
commit
d31d35f81a
2 files changed
+73
-37
No files matched your search
@@ -51,11 +51,28 @@ window.addEventListener('load', function() {
|
||||
const giteaUrl = `${window.location.protocol}//${currentHost}:3000`;
|
||||
const grafanaUrl = `${window.location.protocol}//${currentHost}:3001`;
|
||||
const jenkinsUrl = `${window.location.protocol}//${currentHost}:9095`;
|
||||
// 设置链接的href属性
|
||||
document.getElementById('portainerLink').href = portainerUrl;
|
||||
document.getElementById('giteaLink').href = giteaUrl;
|
||||
document.getElementById('grafanaLink').href = grafanaUrl;
|
||||
document.getElementById('jenkinsLink').href = jenkinsUrl;
|
||||
// 设置链接的href属性和target属性,确保在新标签中打开
|
||||
const portainerLink = document.getElementById('portainerLink');
|
||||
const giteaLink = document.getElementById('giteaLink');
|
||||
const grafanaLink = document.getElementById('grafanaLink');
|
||||
const jenkinsLink = document.getElementById('jenkinsLink');
|
||||
|
||||
if (portainerLink) {
|
||||
portainerLink.href = portainerUrl;
|
||||
portainerLink.target = '_blank';
|
||||
}
|
||||
if (giteaLink) {
|
||||
giteaLink.href = giteaUrl;
|
||||
giteaLink.target = '_blank';
|
||||
}
|
||||
if (grafanaLink) {
|
||||
grafanaLink.href = grafanaUrl;
|
||||
grafanaLink.target = '_blank';
|
||||
}
|
||||
if (jenkinsLink) {
|
||||
jenkinsLink.href = jenkinsUrl;
|
||||
jenkinsLink.target = '_blank';
|
||||
}
|
||||
});
|
||||
|
||||
// 粒子背景效果
|
||||
@@ -358,13 +375,20 @@ serviceCards.forEach(card => {
|
||||
});
|
||||
});
|
||||
|
||||
// 平滑滚动
|
||||
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
// 平滑滚动和链接处理
|
||||
document.querySelectorAll('a').forEach(anchor => {
|
||||
anchor.addEventListener('click', function (e) {
|
||||
const targetId = this.getAttribute('href');
|
||||
// 检查是否是有效的ID选择器(以#开头且不是URL)
|
||||
if (targetId && targetId.startsWith('#') && targetId.length > 1 && !targetId.includes('://')) {
|
||||
const targetElement = document.querySelector(targetId);
|
||||
const href = this.getAttribute('href');
|
||||
const target = this.getAttribute('target');
|
||||
|
||||
// 如果已经设置了target="_blank",让浏览器正常处理跳转
|
||||
if (target === '_blank') {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否是有效的页面内ID选择器(以#开头且不是URL)
|
||||
if (href && href.startsWith('#') && href.length > 1 && !href.includes('://')) {
|
||||
const targetElement = document.querySelector(href);
|
||||
if (targetElement) {
|
||||
// 只在找到目标元素时阻止默认行为
|
||||
e.preventDefault();
|
||||
@@ -373,7 +397,7 @@ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
});
|
||||
}
|
||||
// 如果找不到目标元素,不阻止默认行为
|
||||
} else if (targetId === '#') {
|
||||
} else if (href === '#') {
|
||||
// 处理 href="#" 的情况,滚动到页面顶部
|
||||
e.preventDefault();
|
||||
window.scrollTo({
|
||||
@@ -381,7 +405,11 @@ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
behavior: 'smooth'
|
||||
});
|
||||
}
|
||||
// 对于URL链接等其他情况,不调用e.preventDefault(),允许浏览器正常跳转
|
||||
// 对于URL链接等其他情况,如果没有设置target="_blank",添加它
|
||||
else if (href && !href.startsWith('#') && (href.includes('://') || href.startsWith('//'))) {
|
||||
// 不阻止默认行为,让浏览器处理带target="_blank"的跳转
|
||||
this.target = '_blank';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user