When the button is clicked I need the page to wait for .8s to open the link in the same window, due to a site animation.
This time out code below only works if the href target is _blank
and not if the target is the default _self
- the link then becomes undefined
.
$("#button").click(function() {
setTimeout(function(url) {
window.location = url;
}, 800, linkUrl);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<a href="https://www.w3schools.com"><button id="button">Click</button></a>
How can I fix my code so that it will wait for .8s before the new link is open in the same window when the button is clicked?