I have a requirement where a java script code is there which makes a ajax call and save the user log in database on page load. But the problem is that every time when the user refresh the page the code is getting executed. I want to execute the statement only if the page is refreshed after 10 seconds not on every page refresh. I have to stop executing the code flow if the page is refreshed before 10 seconds.
Execute a javascript code only on refreshing a page after 10 seconds?
200 views Asked by sandy At
2
There are 2 answers
0
On
Can you set cookies? Set the cookie value to current path, on redirect check the cookie value against the current URL. When it matches (so it is a refresh) you can trigger your 10 sec delay by
Logging = setTimout(function() {
Alert("10 seconds passed");
}, 10 * 1000);
To clear the timeout, use
clearTimeout(Logging)
This code executes all 10 seconds (or longer), triggered by a page reload:
You need to store the time (in localStorage), on reload check if now is later than stored time+ 10 seconds: