Block page - please wait
Block page to prevent (mini) DOS.
HTML
HTMLFirst part show an overlay, which is by default hidden (display:none).
The script, disables the button, changes the text, shows the overlay, wait 800 ms and then submits.
<!-- This is the busy overlay, show when Startig quiz... -->
<div class="modal-overlay" id="modalOverlay">
<div class="modal-dialog">
<div class="loader"></div>
<p>Please wait... </p>
</div>
</div>
....
<button type="button" id="submitButton" class=".....">Start</button>
<script>
document.getElementById('submitButton').addEventListener('click', function () {
this.disabled = true;
this.innerText = 'Starting...';
document.getElementById('modalOverlay').style.display = 'block';
setTimeout(function () {
document.getElementById('form').submit();
}, 800);
});
</script>
CSS
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
display: none;
}
.modal-dialog {
position: fixed;
top: 35%;
left: 40%;
background: #fff;
border-radius: 5px;
padding: 20px;
text-align: center;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 2s linear infinite;
margin: 0 auto;
margin-bottom: 10px;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
xx