View Full Version : Exit Surveys and popups

08-30-2007, 10:07 PM
1) Script Title: DHTML Widget V1.02

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

3) Describe problem: Using dhtmlwindow.open function with body tag OnUnload event does not work as expected.

I have a 3rd part survey hosted elsewhere (surveymonkey..nice features!) that I coded up using standard popup javascript and some cookie handling so user only sees it once every 30 days. I had some of our CSRs test this and everyone was using blockers, so using this way to popup windows is useless for the advanced user. Since many of our visitors are not using the latest and greatest browsers, I may still be able to use old-school pop-ups to gather some intel. I used this method just 6 months ago and was able to get 50 surveys in one week. I only need 0.5 to 1% of the users to take the survey to get useful feedback.

Anyway, I created a new DHTML window using the DHTML Widget. I can open it with no problems using an anchor tag. It's when I attempt to use the OnUnload event that there is a clash between what I want to run and one line of code on the last line of the dhtmlwindow.js window.onunload=dhtmlwindow.cleanup. There is more to it that that, but I digress. I think trying to use the DHTML Widget using the OnUnload is the wrong way to approach the problem.

I looked into how to make this work and I am not a JS guru, so I believe that I would have to add an event handler or an event listener...whatever it's called, I just don't have time to play with it anymore. I use the DHTML windows before and it worked for what I needed, but it always takes way longer to customize and blah-blah-blah. So I stopped thinking of how to make it work and asked my self if this is even the right way to go about it.

We use PPC and we know we have a high bounce rate by reviewing Google Analytics. So the idea is to catch people leaving the site and ask them why they are leaving. It a 5-10 second 4 question survey. Its really easy for a user to fill out. ALSO, if you use Google PPC, Google will NOT allow you to use a popup on a landing page - they don't to see a popup window when you land on the page or when you clicks away. So I am thinking of just using the popup after the first page and only on certain pages.

So here are my questions:

Is any one using popup surveys and how are you displaying them?
If you are using surveys, what kind of responses do you get and has it helped you make changes to your website?
Am I better off displaying a link prominently on the landing page?

P.S. If there is a better website to post this kind of question, please point me in the right direction.

08-31-2007, 03:54 AM
Well it's fairly painless to get the DHTML window to load onunload of the document, but then you run into the real problem- The DHTML window like the rest of the page is gone and not seen as the user is taken to the other page. Popup windows can be launched onunload because it creates a new physical window, while the DHTML window is just a simulated window that's part of the page it's embedded on, not a new browser window.

FYI to get the DHTML window to launch onunload (except no one can see it that way), you can do this:

function wrapperwin(){
var googlewin=dhtmlwindow.open("googlebox", "iframe", "http://images.google.com/", "#1: Google Web site", "width=590px,height=350px,resize=1,scrolling=1,center=1", "recal")

googlewin.onclose=function(){ //Run custom code when window is being closed (return false to cancel action):
return window.confirm("Close window 1?")

if (window.addEventListener)
window.addEventListener("unload", wrapperwin, false)
else if (window.attachEvent)
window.attachEvent("onunload", wrapperwin)

08-31-2007, 11:26 AM
Thanks for that posting. I also realized this, but without posting that detail, the simulated popup is part of the page and not a workable solution. That is why I was asking how other do it. I will likey have to use a OnLoad event somewhere else on the site a few clicks downstream requesting for visitors to fill out a survey or going back to the standard JS popup using the onunload event and hope to not be blocked enough to gather some data.


08-31-2007, 07:12 PM
So you're just looking for a popup window script that loads when the page unloads, and doesn't conflict with the DHTML window widget? Try the below one then:

<script type="text/javascript">

//Pop-under window- By JavaScript Kit
//Credit notice must stay intact for use
//Visit http://javascriptkit.com for this script

//specify page to pop-under
var popunder="http://yahoo.com"

//specify popunder window features
//set 1 to enable a particular feature, 0 to disable
var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0"

//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=0

///No editing beyond here required/////

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
return returnvalue;

function loadornot(){
if (get_cookie('popunder')==''){

function loadpopunder(){

function wrapperwin(){
if (once_per_session==0)

if (window.addEventListener)
window.addEventListener("unload", wrapperwin, false)
else if (window.attachEvent)
window.attachEvent("onunload", wrapperwin)


It's based on this script (http://www.javascriptkit.com/script/script2/popunder.shtml), though I've modified it to launch when the page unloads.

10-03-2007, 09:33 AM

I would also like to use this script for a survey pop-up, except I'm not worried about it opening onUnload. Just onload is fine for me.
The thing I don't know is how to make the window only pop-up to people who haven't seen it recently.
I know this would be done with cokkies but I'm not sure how to do this...

Could anyone help me out?