D
D
Denis2021-07-19 14:55:31
JavaScript
Denis, 2021-07-19 14:55:31

How to make it so that when you click on the button, it follows the link with a delay?

Hello, how in javascript to make it so that when you click on the button, 3 seconds pass and then follow the link?

That is, the transition to the link with a delay.
Thanks in advance, I will be very grateful

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2021-07-19
@den1312

button.addEventListener('click', function(evt){
  evt.preventDefault();
  setTimeout(function(){
    location.href = '//google.com';
  }, 3000) // 3000 ms = 3s
});

E
Evgeniy, 2021-07-19
@Zheleznov

in button insert onclick="golink()"

function golink() {
    setTimeout(function() {  
          document.location.href = "https://www.site.ru";
    }, 3000);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question