Exit Popup Message

A lot of marketing site needs exit popup message. I seen lot of bloated plugging which does the job. This one is cool and simple.

<!– Exit Message –>
<script type=”text/javascript”>
window.onload = function(){

var allowUnload = true;

window.onbeforeunload = function(e){
//allowUnload will allow us to see if user recently clicked something if so we wont allow the beforeunload.
//message to be returned to the popup box.
var message = ‘Are you sure you want to leave the page.’,
e = e||window.event;
e.returnValue=message; // IE
return message; // Safari
// We need this to allow us to see if user has clicked anywhere if user has clicked we wont allow beforeunload to run.
document.getElementsByTagName(‘body’)[0].onclick = function(){
allowUnload = false;
//setTimeout so we can reset allowUnload incase user didn’t leave the page but randomly clicked.
setTimeout(function(){ allowUnload = true; },100);