![图片[1]-少年精品音频资源网-vst76.cn-vst76资源网-宿主-精选插件-少年音频资源网-少年音频-音频设备-少年音频工作室-WWW.VST76.CN-www.vst76.cn-少年精品资源网-少年资源网子比主题美化 – 文章页 “zibll文件下载” 和 “文章卡片” 模块在新窗口打开教程](https://www.vst76.cn/wp-content/uploads/2024/11/image-124.png)
教程
加入以下代码到主题的自定义javascript代码里面
两个任选其一
一 文章页所有外链在新窗口打开
window.onload = function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (links[i].href.includes('?golink=')) {
links[i].setAttribute('target', '_blank');
}
}
};
二 只有文件下载模块在新窗口打开
document.addEventListener('DOMContentLoaded', function() {
var downloadButtons = document.querySelectorAll('.file-download-btn');
downloadButtons.forEach(function(button) {
button.addEventListener('click', function(event) {
event.preventDefault();
window.open(this.getAttribute('href'), '_blank');
});
});
});
文章卡片新窗口打开
document.addEventListener('DOMContentLoaded', function() {
var links = document.querySelectorAll('.wp-block-zibllblock-postsbox a');
links.forEach(function(link) {
link.addEventListener('click', function(event) {
event.preventDefault();
window.open(this.href, '_blank');
});
});
});
文件下载和文章卡片二合一
document.addEventListener('DOMContentLoaded', function() {
function handleLinkClick(event) {
event.preventDefault();
window.open(this.getAttribute('href') || this.href, '_blank');
}
var links = document.querySelectorAll('.wp-block-zibllblock-postsbox a, .file-download-btn');
links.forEach(function(element) {
element.addEventListener('click', handleLinkClick);
});
});
© 版权声明
THE END
















暂无评论内容