View Full Version : DHTML Modal window (on exit)

01-03-2009, 10:13 PM
DHTML Modal window v1.1

Hello everyone! :o
Can you please tell me if I can edit this script for the window to appear on page exit?
I would be grateful for any help.

01-04-2009, 12:30 AM
The only thing that can use the onunload attribute is the alert types(uhh.. I think?).
You cannot get a modal window to show onunload, but you can do something like:

<body onunload="alert('Bye');">

Sorry. :(

01-04-2009, 07:27 AM
Thanks for the input. :o

I've seen sites that have drop-in windows on page exit. Does anyone else know how I can trigger that on page exit as opposed to onClick or on page load?

01-04-2009, 07:32 AM
Can you give me an example of a site?

01-04-2009, 04:01 PM
Try to use onbeforeunload event instead.

01-04-2009, 10:34 PM
Can you give me an example of a site?

HERE (http://www.trafficregenerator.com/) is an example of a paid script that does it. But I've seen goodbye popups that do the same thing, I just have to think and remember where. Ideally I'd like to use the Dynamic Drive DHTML Modal window one to do the goodbye thing. :o

01-04-2009, 10:36 PM
Try to use onbeforeunload event instead.

Ok I will try that tonight when I get home. :)

01-04-2009, 10:45 PM
That script activates when it can't detect your cursor - not when you close the window.

01-04-2009, 11:15 PM
Oh, really?! :p

Both would be nice: when they go to leave the page or when their cursor leaves the screen. I'd like to play sround with both of them. Is it simple to do that kind (when you can't see the cursor)?

01-04-2009, 11:17 PM
P.S. I didn't mean both together, I mean one or the other. Just that I'll play around with both.

01-05-2009, 12:39 AM
Here you go:

<script type="text/javascript">
var div="page_go";
var _ = function(el) { return document.getElementById(el); };
window.onmousemove = function(e){
if(e.pageY <=2 && e.pageX >= 0){
<style type="text/css">
* { margin: 0; }
#page_go {
width: 100%;
height: 100px;
text-align: center;
visibility: hidden;
font-family: georgia;
border: 1px solid #404040;
background: #E5E9FF;
<div id="page_go">
<h1>Don't go!!</h1>