[英]JavaScript - set timeout script
I am trying to use inline javascript to set a timeout for a link I am calling on my website:我正在尝试使用内联 javascript 为我在我的网站上调用的链接设置超时:
<a href="javascript:setTimeout(()=>{window.location = 'thankyou.html' },2500);" class="burst_1 btn">Elementary School Camp</a>
It works in Chrome but not in Firefox or Internet Explorer.它适用于 Chrome,但不适用于 Firefox 或 Internet Explorer。 I tried to search online for alternatives but nothing has worked for me so far.
我试图在网上搜索替代品,但到目前为止没有任何效果。 I need a timeout because the buttons I am using on my site have a fireworks effect and I'd like visitors to see the effect for a few seconds before they get sent to the link page.
我需要超时,因为我在我的网站上使用的按钮有烟花效果,我希望访问者在他们被发送到链接页面之前看到效果几秒钟。
Or is there a better way to achieve what I am trying to do?或者有没有更好的方法来实现我想要做的事情? Open to suggestions.
对建议持开放态度。
Replace <a href="javascript:...">
by <a href="#" onclick="...">
:将
<a href="javascript:...">
替换为<a href="#" onclick="...">
:
function waitThenNavigateTo (newLocation) { setTimeout(() => { window.location = newLocation; }, 1000); }
<a href="#" onclick="waitThenNavigateTo('http://example.com')">Click me!</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.