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);




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s