Link to home
Start Free TrialLog in
Avatar of mmoline
mmoline

asked on

onUnload function, quick 200 pts...

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
ASKER CERTIFIED SOLUTION
Avatar of a.marsh
a.marsh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of a.marsh
a.marsh

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
Avatar of mmoline

ASKER

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
Avatar of mmoline

ASKER

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
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.
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
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
Avatar of mmoline

ASKER

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
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