Using setTimeout we can trigger an alert after 5000 milliseconds.
setTimeout("alert('hello guest!')",5000);
<form> <input type="button" value="Click for event" /> </form>
That’s the elegant way to handle delays, pauses and waiting in Javascript.
The routine above doesn’t stop the Javascript routine from executing. It just sets up an event to happen later. But sometimes you find yourself thinking: It would be so much easier if I could just get Javascript to wait for a bit here and then carry on as before. It's a bit naughty, but I’ve written a script that does just that. Note: This script is not a good example of how to use Javascript. It consumes a huge amount of CPU power just going round in circles for a predetermined amount of time. You really should be using the technique above in nearly all cases, but this script can be handy for prototyping. Simple way:
<script language="javascript">
function dopause(msec) {
msec += new Date().getTime();
while (new Date() < msec){}
}
</script>
Call the routine dopause(5000) where 5000 is the number of milliseconds you would like the computer to pause. You're welcome to use this script on your site and to adapt it to suit.
A great font/script for creating beautiful logos, posters, wedding invitations, blog posts, social media, and…
Realistic T-Shirt Mockup PSD which you can use freely to showcase your apparel design.
Classic coffee mug Mock-up Free PSD. Free mug mockup PSD to showcase your branding design…
Juliette - Stylish Handwritten Signature Font
XXII Aven Font Family - a new modern all-caps sans serif font with versatility in creativity.