How to pause execution of javascript code?

Good afternoon.
Here is the script after sending message redirect to another page:
the <script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
 location = 'https://mysite.ru/spasibo-za-otpravlennoe-soobshhenie/';
}, false );
</script>

Prompt how to add in the code a small time delay, e.g. 3 seconds to execute the script?
June 5th 19 at 21:39
4 answers
June 5th 19 at 21:41
Solution
the <script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
 setTimeout(function() {
 location = 'https://mysite.ru/spasibo-za-otpravlennoe-soobshhenie/';
 }, 3000); // delay in milliseconds
}, false );
</script>

https://learn.javascript.ru/settimeout-setinterval
June 5th 19 at 21:43
a time delay, e.g. 3 seconds to execute the script

try this
document.addEventListener( 'wpcf7mailsent', function( event ) {
setTimeout(function(){
 document.location = 'https://mysite.ru/spasibo-za-otpravlennoe-soobshhenie/';
 }, 3000);
}, false );
June 5th 19 at 21:45
document.addEventListener( 'wpcf7mailsent', function( event ) {
 setTimeout(function() {
 location = 'https://mysite.ru/spasibo-za-otpravlennoe-soobshhenie/';
 }, 3000);
}, false );
June 5th 19 at 21:47
Thank you all very much!

Find more questions by tags JavaScript