Unstoppable Domains

Message Before Browser Exit

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
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
•••
[FONT=Helvetica,Arial]onunload[/FONT]
 
0
•••
Don't do it. It's annoying.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back