Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop up window on leaving a site

Status
Not open for further replies.

nm61

Programmer
Joined
May 25, 2004
Messages
14
Location
CA
Hello
I have a multi page web site and I am tying to add a pop up window with a small survey that will open when the user finishes browsing and leave the whole site not just one page. Is there a way to do this. Many thanks for any help.
 

I'm not sure that this will be possible, unless browsers honour setTimeout threads after the executing page has been closed.

Dan


The answers you get are only as good as the information you give!

 
I don't think so, because you need to know where the person is going when they close or redirect the window. If there was an onNavigate event or something, this would be a breeze. I suppose you could have a child window monitor the URL of the parent window, but this would get annoying for your users and XP SP2 might block it anyway. An ActiveX control might be able to handle it, but then again it'd be a pain in the ass to deploy it to all of your users. The only feasible answer I can think of is to monitor all mouse clicks. If a link was clicked, make a note of it. This way, you'll know if the page is being unloaded due to a link on your page. Here's a start:
Code:
document.onmousedown = checkLink;
window.onbeforeunload = windowClose;
Popup = 0;

function checkLink() {
obj = window.event.srcElement;
Temp = window.location.hostname;
Local = Temp.replace(/[URL unfurl="true"]www./g,"");[/URL]
	if ((event.button == 1) && (obj.tagName == "A")) {
		URL = obj.href;
		Pos = URL.indexOf('/',7);
		Temp = URL.substr(7,Pos-7);
		Domain = Temp.replace(/[URL unfurl="true"]www./g,"");[/URL]
			if (Domain != Local) {
				Popup = 1;
			}
	}
}

function windowClose() {
	if (Popup == 1) {
		window.open('survey.html','pollWindow','resizable=no,status=no');
	}
}
I'm sure this code can be optimized, but it's a start :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top