This question already has answers here:
I want to delay a link for a period of 500 with javascript
(5 answers)
Closed 6 years ago.
Is it possible to delay a hyperlink by 3 seconds as CSS has the delay animation, I have some icons with animation on them, for a mobile user they cant hover over the icons, but they would be able to see the icon animation if i had a delay on the hyperlinks?
Is this possible?
Thanks All!
Related post: I want to delay a link for a period of 500 with javascript
In summary:
HTML:
Javascript:
function delay (URL, ms) {
setTimeout( function() { window.location = URL }, ms);
}
Related
This question already has answers here:
How to reload page every 5 seconds?
(11 answers)
Closed 2 years ago.
This only refreshes the page once, I have tested it. How do I make it reload the page every 5 seconds and look for an element then click on it?
function reload() {
document.location.reload();
}
setTimeout(reload, 5000);
Hopefully this is what you're looking for.
setTimeout(() => {
const button = document.querySelector('.button');
button.dispatchEvent(new MouseEvent('click'));
window.location.reload();
}, 5000)
This question already has answers here:
How to set time delay in javascript
(10 answers)
Closed 4 years ago.
I want to make a time delay in my website. So far I have built a sleep function which can freeze my system for number of seconds. But with this, I'm not able to my access the User Interface of the website.
My Code:
<html>
<head>
<title></title>
</head>
<body>
<button onclick="on_click()">Button-1</button>
<button onclick="console.log('BYE');">Button-2</button>
<script>
function on_click()
{
sleep(15000);
console.log("HI");
}
function sleep(delay)
{
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
</script>
</body>
</html>
So whenever I click Button-1, I'll have to wait for the 15 seconds to click the Button-2. I want my program to allow me to click on Button-1 and it should wait for 15 seconds and display "Hi" on the console. And also allowing me to click Button-2. Please Help. Thanks
The setTimeout function allows you to set a time delay without stopping the script from running ongoing processes.
This question already has answers here:
jquery/javascript alert popup on a set time
(2 answers)
Closed 5 years ago.
i have a bootstrap modal popup with following code that runs every time page loads.
I need the script run once for each session with cookie and cookie will expire after 5 minutes. can you please help?
here's the code:
$(window).on('load',function(){
$('#myModal').modal('show');
});
setInterval(showModal, 300000);
function showModal()
{
$('#myModal').modal('show');
}
This question already has answers here:
How to schedule IE page reload
(4 answers)
Closed 8 years ago.
here's my problem: i need to display a message for a while, and then reload the page.
can someone tell me how to reload a page, after certain delay?
You don't even need jQuery or HTML5 for this:
setTimeout(location.reload.bind(location), 60000);
This will wait 1 minute (60,000 milliseconds), then call the location.reload function, which is a built-in function to refresh the page.
setTimeout(function(){
window.location.reload(); // you can pass true to reload function to ignore the client cache and reload from the server
},delayTime); //delayTime should be written in milliseconds e.g. 1000 which equals 1 second
Update:
One-liner using ES6:
setTimeout(() => window.location.reload(), delayTime);
You may try this without js, it cycles:
<meta http-equiv="refresh" content="5"/> <!-- 5 sec interval-->
<h1>Page refersh in every 5 seconds...</h1>
You can even navigate to a different page, visiting google home page
<meta http-equiv="refresh" content="5;http://www.google.com"/> <!-- 5 sec delay-->
<h1>Redirecting in 5 seconds...</h1>
This question already has answers here:
JavaScript alert box with timer
(11 answers)
Closed 9 years ago.
For my website I would like an alert box message to appear 4 seconds after the page is opened. I cant figure out how to do this as the timed function works if a button is clicked but I would like the alert box to pop up automatically withoutt any user input/button and then shut when the user clicks "okay"...
Any ideas or posts related to this topic would be great help!
Thanks
<script type = "text/javascript">
window.onload=function(){setTimeout(showPopup,4000)};
function showPopup()
{
//write functionality for the code here
}
</script>
In it's most simple form:
setTimeout(function(){alert("Hello")},4000);
4000 = 4 seconds
If you want an alert to appear after a certain about time use this code:
setTimeout(function() { alert("Your Message"); }, time);