Solved

onUnload function, quick 200 pts...

Posted on 2001-06-18
9
232 Views
Last Modified: 2008-02-26
I am trying to pop up a window (an exit page if you will) that will open when a visitor LEAVES the website.  I am currently using the onUnload function, which displays my popup every time you refresh, or even go to a different page within the site.  This won't work.  I need to display the window (a page I have created called exit.htm) ONLY when the site is exited.

I know this can be done. (anyone who has ever stumbled upon an adult site knows what I am talking about) But, for the life of me I cannot find the right code...

This is time sensitive, which is why I am offering 200 pts. for the question..

Help,

mmoline
0
Comment
Question by:mmoline
9 Comments
 
LVL 15

Accepted Solution

by:
a.marsh earned 200 total points
ID: 6204322
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6204338
An slight alternative:

http://developer.irt.org/script/695.htm

You would simply put it in any link that took the user away from the site.

The only time you are really "stuck" is if the user types something in the address bar to leave the site...

:o)

Ant
0
 

Author Comment

by:mmoline
ID: 6204357
Marsh,

I don't think this is what I am looking for unless I am not understanding..  I have been to sites where if I type in a different URL, and leave the site, or if I close the browser window, the pop up appears.  I don't want to have to attach it to links (which is what this script looks like??) and I don't want it to appear on a refresh.

Any ideas??

mmoline
0
 

Author Comment

by:mmoline
ID: 6204358
Marsh,

I don't think this is what I am looking for unless I am not understanding..  I have been to sites where if I type in a different URL, and leave the site, or if I close the browser window, the pop up appears.  I don't want to have to attach it to links (which is what this script looks like??) and I don't want it to appear on a refresh.

Any ideas??

mmoline
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:kamcheungon
ID: 6204632
Not sure if that really works, but it should:

1) Let's say someone go to your site, url: http://www.mysite.com/page1.html.

2) When page1.html is brought up, use javascript to open a new window that doesn't have scrollbar, menubar, status bar, location and set it to very small. From now on, let's call the big window, winA, the new small window winB.

3) Assign a handler "opener" to the main window.

4) In winB, use setTimeout to check the main window's location every, say 5 sec. If the location is not a page, an alert will then be displayed.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6204811
try

<html>
<head>
     <title>Untitled</title>
     <SCRIPT>
     
function hUnload()
{
mydomain='www.yoursite.com'
if(document.location.href.indexOf(mydomain)==-1)
{
window.open('popup.htm')
}
}
document.onunload=hUnload;
</SCRIPT>
</head>

<body onunload="hUnload()">

<A HREF="http://www.microsoft.com">ms</A>

</body>
</html>



Bob
0
 
LVL 5

Expert Comment

by:nilapenn
ID: 6204905
Try This

<SCRIPT LANGUAGE="JavaScript">
<!--
function RorC() {

var top=self.screenTop;
if (top>9000)
{alert('window was closed')}
else
{alert('window was Refreshed')}
}

//-->
</SCRIPT>

</HEAD>
<BODY BGCOLOR="#FFFFFF" onunload="javascript:if (document.all){RorC()} else {var top=window.outerWidth;if
(top==0) {opener.alert('window was closed')} else {opener.alert('window was Refreshed')}}">
gfds
0
 

Author Comment

by:mmoline
ID: 6205160
Thanks Marsh,

This appeared to be the only way to really accomplish what I wanted.  However, I still have not solved the problem of not popping up the window on refresh..

I am awarding you the points, thanks again...

mmoline
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6205611
Glad to help...

The way I would really recommend using then is this way:

http://developer.irt.org/script/695.htm

You simply use the onClick for any link that takes the user away from the site - and since you are not using onunload at all, then the refresh won't be a problem.

You can adapt it quite easily so that rather than the onClick containing the window.open function it simply calls a function which contains the window.open function - that way if the page the appeared in the popup window needed to change you would only have to alter the code in one place rather than in every link.

:o)

Ant
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now