Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to delay a link for a period of 500 with javascript

I've been looking through the Stackoverflow questions, trying to get help with a simple link delay; I want to put it around a div, and I can't make heads or tails of the examples I've found.

So far, I understand that I need to halt the native function of href, but I don't know how to do that. The code is still very alien to me. Help?

like image 282
ammonhra Avatar asked Jan 21 '13 08:01

ammonhra


People also ask

How do you make a delay in JavaScript?

The standard way of creating a delay in JavaScript is to use its setTimeout method. For example: console. log("Hello"); setTimeout(() => { console.

What is delay () in JavaScript?

The delay is set in milliseconds and 1,000 milliseconds equals 1 second. If the delay is omitted from the setTimeout() method, then the delay is set to 0 and the function will execute.

What we can use instead of setTimeout in JavaScript?

The setTimeout() is executed only once. If you need repeated executions, use setInterval() instead. Use the clearTimeout() method to prevent the function from starting.


1 Answers

Set your href attribute as href="javascript:delay('URL')" and JavaScript:

function delay (URL) {
    setTimeout( function() { window.location = URL }, 500 );
}
like image 72
gurvinder372 Avatar answered Sep 25 '22 14:09

gurvinder372