Message Before Browser Exit

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

mike22

New Member
Impact
0
Does anyone know how the following can be done?

1. Is there a code I can implement that will trigger some type of message or popup when a visitor decides to leave from any one of the following methods:

a. closes the browser
b. hits the back button
c. enters a new url in the address bar
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Add this to your index file:
PHP:
<script type="text/javascript" src="exitPop.js">

Make a new file with following code and rename to exitPop.js
PHP:
var ExitPopURL = 'http://www.myDomain.com/userexit.php';
var AlertBox = "*****************************************************\n\n Stop!!\n\nBefore leaving, please give a quick survey on how we doing and share your suggestions.\n\nThanks for visiting myDomain.com.\n\n   \n\n*****************************************************";

window.onload = function(){
	createExitPop();
}
function ajaxGET(divId, page, effect) 
{ 
     var xmlHttp; 
     try 
    { 
         xmlHttp=new XMLHttpRequest(); 
    } 
     catch(e)   
    { 
         try 
         { 
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
         } 
         catch(e)   
          { 
               try 
               { 
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
               } 
               catch(e)   
             {      
                    alert("Error"); 
                  return false; 
             } 
         } 
     } 
      
    xmlHttp.onreadystatechange=function() 
     { 
         if(xmlHttp.readyState==4) 
          { 
               if(effect == 'collapse') { document.getElementById(divId).style.display='none'; } 
               else                     { document.getElementById(divId).innerHTML=xmlHttp.responseText; } 
         } 
    } 
     xmlHttp.open("GET",page,true); 
    xmlHttp.send(null); 
}

function createExitPop()
{
	var theBody = document.getElementsByTagName('body')[0]; 
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id','ExitDiv');
	theBody.setAttribute('id','body');
	newdiv.setAttribute('style', 'width: 100%; height: 100%;');
		theBody.appendChild(newdiv);
		document.getElementById('ExitDiv').value = ajaxGET('ExitDiv', ExitPopURL);
	document.getElementById('ExitDiv').style.display = "none"; 
	document.getElementById('ExitDiv').style.top = '0px'; 
	document.getElementById('ExitDiv').style.left = '0px'; 
	document.getElementById('ExitDiv').style.position = 'relative'; 
	document.getElementById('ExitDiv').style.backgroundColor = '#FFFFFF';	
}
isExit = true;

function ExitPop(isExit) {
		if(isExit != false)	{
			isExit=false;
			isPop = true;
			var bodyTag = document.getElementById? document.getElementsByTagName("BODY")[0] : document.body;
			bodyTag.setAttribute("id", "body");
			bodyTag.innerHTML = document.getElementById('ExitDiv').innerHTML;
			return AlertBox;
		}
	}
window.onbeforeunload = function(){
		return ExitPop(isExit);
	
}
 
Last edited:
0
Close
[FONT=Helvetica,Arial]onunload[/FONT]
 
0
Close
Don't do it. It's annoying.
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back