Solved

onUnload function, quick 200 pts...

Posted on 2001-06-18
9
237 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create an automated page index 9 53
jQuery Scroll To Top 5 40
jQuery force form POST 7 53
Possible propagation problem 1 25
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

821 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