Click to See Complete Forum and Search --> : Pop up only when user leaves site


metaphiz
07-10-2003, 09:43 AM
I want to pop up a window that opens if the user leaves our domain. If they stay within the domain, the pop up can't open. This isn't for annoying hazardous pop-ups but just for a brief user survey for customer service puposes.

Does anyone have any suggestions, or especially CODE to do this?

Charles
07-10-2003, 09:55 AM
"[A] brief user survey for customer service puposes" is an "annoying hazardous pop-up". The following will work well enough that at least some of yor users will never come back.

1) Give the links to any external sites a class of "external".

2) Include you horrid popup in the document's HEAD element.

2) Put the following in each document's HEAD element.

onload = function () {for (i=0; i<document.links.length; i++) {if document.links[i].class != 'external') {document.links[i].onclick = function () {self.onunload = function () {}}}}}

man
07-10-2003, 11:00 AM
<html>

<head>


<SCRIPT LANGUAGE="JavaScript">
<!--
//
loc=location.href;
pos=loc.indexOf("indexb.htm");
loc1=loc.substring(0,pos);
function leave() {
windowIMA=window.open("",'','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,status=no,resizable=0,width=240, height=240')
windowIMA.document.write("<HTML><TITLE>Info POP-UP...</TITLE>"
+"<BODY BGCOLOR='ffffff' text= '000000'><CENTER>"
+"<FORM METHOD=GET ACTION='+loc1+'>"
+"<P><B>Your Text here....
+"<br>...and here"
+"</FORM><BR>");
}

// -->
</SCRIPT>

</head>

<BODY ONUNLOAD="leave()">

</body>

</html>

metaphiz
07-10-2003, 11:52 AM
I tried this code but I think I missed the customizations. What do I have to change with the code you've posted to get it to work with my pages? Thanks.

man
07-10-2003, 12:32 PM
The following part of the code must stand in one line!!!

...
windowIMA=window.open"" ,'','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,status=no,resizable=0,width=240, height=240')
...

Hope it works now...

metaphiz
07-10-2003, 01:15 PM
The line you mentioned WAS broken incorrectly in the middle. I fixed that but still no luck. Where do I refer to the page that will pop up? Or do I have to insert the entire popup page in the script where you say 'your text here'? If so this may not work because the page i need to pop us is a survey form and I'm not sure if you can nest form tags. I really appreciate your help. Gotta get this working!

Here's the page:

http://www.softwarecraze.com/test_exit/checkout_page_example6.html

Charles
07-10-2003, 02:46 PM
Given that the file you want in the popup is http://www.w3.org/TR/WCAG10/ then

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
<!--
onload = function () {for (i=0; i<document.links.length; i++) {if (document.links[i].hostname == location.hostname) {document.links[i].onclick = function () {window.onunload = function () {}}}}}

onunload = function () {window.open('http://www.w3.org/TR/WCAG10/', 'child', 'height=400,width=300')};
// -->
</script>
<ul>
<li><a href="local.html">Local File</a></li>
<li><a href="http://www.w3.org/">W3C</a></li>
</ul>

kdcgrohl
07-10-2003, 04:47 PM
if you want a popup on leaving the site and not upon changing the page(onUnload), browse my javascript section @ kdcgrohl.com (http://www.kdcgrohl.com) for popup on site exit.

metaphiz
07-10-2003, 05:05 PM
I appreciate your help, but what I need is a script that will open a pop-up whenever the user leaves our site from a single page of the site. It's in the middle of the shopping cart so there are many links within the site that shouldn't trigger the pop-up. We want the user to be able to keep shopping if they change their mind in the middle of the cart.

The script you provide would work on a page where there were lots of links to external sites, but our page has none. I'm more concerned with the user going to bookmarks to leave the page, or typing in a URL in the browser.

metaphiz
07-10-2003, 05:19 PM
Thanks for your help kdcgrohl, but I looked at your script and it looks like the popup would come up if you left the site from any page. One of the specs of the assigment is that the window only pop up if the user leaves the site from a single page. The page is a shopping cart page and we want to post a survey about why they are not continuing to shop, or finishing their purchase.

Can you think of a way to use your script to this effect?