I have a button with an "onclick" function that disables the button for 15 seconds. After that it will be automatically clickable, but in between 15 seconds of time period after a click, if I do refresh the page, it doesn't count the remaining seconds and the button is now clickable.
function up(){
$(document).ready(function () {
$("#upside").attr("disabled", true);
document.getElementById("downside").disabled = true;
setTimeout(function () {
$("#upside").removeAttr("disabled");
$("#downside").removeAttr("disabled");
window.location ='/Balnce_add';
},15000);
});
}
And here is my HTML button code:
<button id="upside" onclick="up()" type="submit" class="btn btn-success">Up</button>
$(document).ready()inside an event handler like that. And when the page is refreshed, everything about the previous page will be gone; nothing survives that transition, including your timeout handler.sessionStorage. When you disable the button, save the start time in session storage. When the page reloads, get the start time from session storage, disable the button if it's <15 seconds since then, and start another timer to re-enable the button.