Popup Survey when Leaving domain

Posted on 2004-10-07
Last Modified: 2008-02-07
I need to launch a shopper survey when the shopper leaves the website.
This means the survey must appear if the visitor:
A) navigates to a different domain,   or
B) closes the browser

The survey must popup reliably for any user regardless of browser.
This is VERY important to this e-commerce site, please help!
Question by:DougCoulter
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 33

Expert Comment

ID: 12255905
<body onunload ="CallFunction()">

Where  the CallFunction will be something like
function CallFunction()
{ ("popup.html","popup:)
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI


Author Comment

ID: 12256391

your approach creates a pop-up when leaving the domain BUT
also when remaining within the domain.

LVL 33

Accepted Solution

sajuks earned 250 total points
ID: 12256501
// this code should've worked for you
function checkExit(){
     var win ="","","width=10,height=10");
     win.document.write("function checkDomain(){ ");
     win.document.write("try {");
     win.document.write("if(window.opener) var x = window.opener.location.href;\n");
     win.document.write("catch(e){window.alert(\'you left my domain!!!\'); self.close();}");

<body onunload="checkExit();">
<a href="closeDomain.html">stay at domain</a><br>
<a href="">leave domain</a><br>

Author Comment

ID: 12256610
i can generate an alert with this but i need to generate a popup asp survey form.
will it work for something like:
win.document.write("catch(e){var win ='survey.asp','survey','height=650,width=500');}");
LVL 33

Expert Comment

ID: 12256742
Oh yes.Thats should work
Are you getting any errors?

Author Comment

ID: 12256785
not getting the pop-up.

i need to make a database entry and launch an asp form based on the visitor leaving the domain.
the database code is simply:
<% sql = 'UPDATE tracking SET survey2 = '1' WHERE sessionID='" + Session.SessionID + "'";
in asp. . . . . . .is there some way to execute that as part of the checkExit function?
LVL 33

Expert Comment

ID: 12256834
In the example were you getting the alert right ?
That means there must be something wrong in the windows open script.
This works for me
win.document.write("catch(e){var win ='survey.asp','survey','height=650,width=500');}");

Are you sure that the popup is not closed by any popup killer ( like google toolbar or firewall?)

Author Comment

ID: 12263297

I can get the alert,
I get the initial 10x10 window,
but I am unable to get another window to popup.

So, you're right, there must be something wrong with the the windows open script,
there is no problem with popup blockers, i can get popups when there are no conditionals.

i have tried:
win.document.write("catch(e){var win ='survey.asp','survey','height=650,width=500');}");
which seems like a simple replacement for the alert, but no luck.

Any suggestions?

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question