you could hook the onbeforeunload event, and have a overlay element hidden, then show it inside the event
overlay element
<div id="dark-overlay" style=""></div>
css
#dark-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
opacity: 0.6;
z-index: 1000;
display: none;
}
javascript
<script type="text/javascript">
window.onbeforeunload = function(event){
var overlayelement = document.getElementById('dark-overlay');
overlayelement.style.display = 'block';
return 'are you sure you want to quit?';
}
</script>
note this won't exactly achieve what you asked: it will show an overlay, along with a browser confirm dialog containing the text you returned.
I couldn't think of a way to wait a second before exiting, except putting a loop that exits after the defined amount of time which is terribly inefficient.