/    Sign up×
Community /Pin to ProfileBookmark

Pop up only when user leaves site

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?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJul 10.2003 — [font=georgia]"[A] brief user survey for customer service puposes" [i]is[/i] 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.[/font]

[font=monospace]onload = function () {for (i=0; i<document.links.length; i++) {if document.links[i].class != 'external') {document.links[i].onclick = function () {self.onunload = function () {}}}}}[/font]
Copy linkTweet thisAlerts:
@manJul 10.2003 — <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>
Copy linkTweet thisAlerts:
@metaphizauthorJul 10.2003 — 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.
Copy linkTweet thisAlerts:
@manJul 10.2003 — 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...
Copy linkTweet thisAlerts:
@metaphizauthorJul 10.2003 — 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
Copy linkTweet thisAlerts:
@CharlesJul 10.2003 — [font=georgia]Given that the file you want in the popup is http://www.w3.org/TR/WCAG10/ then [/font]

[font=monospace]<!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>[/font]
Copy linkTweet thisAlerts:
@kdcgrohlJul 10.2003 — if you want a popup on leaving the site and not upon changing the page(onUnload), browse my javascript section @ [URL=http://www.kdcgrohl.com]kdcgrohl.com[/URL] for popup on site exit.
Copy linkTweet thisAlerts:
@metaphizauthorJul 10.2003 — 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.
Copy linkTweet thisAlerts:
@metaphizauthorJul 10.2003 — 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?
×

Success!

Help @metaphiz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...