javascript - setTimeOut 延迟从 html 中的 url 加载 href - 不工作
问题描述
href
我在所有页面上都有一个链接,每次用户单击它时,我都想延迟从带有<a>
标签的下一页加载。我试图<a>
在 HTML 中的标记中获取链接,然后尝试延迟它,但超时不起作用。任何人都可以帮忙吗?
var link = document.querySelector('a').getAttribute('href')
setTimeout(function() {
location.href = link
}, 4000);
解决方案
我相信这会帮助你:
const a = document.querySelector('a');
a.addEventListener("click", (e) => {
e.preventDefault();
const link = e.target.href;
setTimeout(() => {
window.open(link)
}, 1000)
})
推荐阅读
- dart - 颤振错误:无法将参数类型“Future”分配给参数类型“Widget”
- javascript - 从反应到节点获取url参数
- c - 说明符 %[^s] 用于什么?
- node.js - 没有自定义授权者的 AWS lambda 基本身份验证
- c# - AspNetCore.Mvc.Core 版本不匹配
- authentication - sp 发起 saml sso 认证
- node.js - 如何将通过 stidn 管道传入的数据用于 fs.createReadStream
- android - ImageVIew 略超出父视图
- android - android中的MVVM,在不破坏模式的情况下访问assetManager
- python - 删除字符串列表中的所有数字