I do something similar in a application that I have created which consist of
several pages of data-entry.  The client complained that some user would
lose their data because they would navigate away without realizing that the
data wasn't being saved.  I created a JavaScript that would fire on the
unload event.  Of course in the first version, the message would appear
every time you left the page even if you pressed the submit button.  I came
up with a way to set a Boolean variable that would be checked when leaving
the page, if it was true, I would let the user go, if it was false I would
give them the message.

Anyway, now that I have bored you, here is a snippet of code that will do
what you want:

<html>
<head>
        <title>PopUp Demo</title>
<script language="JavaScript" type="text/javascript">
var bNavSafe = false;

function popUp(sURL,iWidth,iHeight) {
    popWin = window.open(sURL,'popWin',
                'toolbar=0,location=0,directories=0,status=0,menubar=0,' +
                'scrollbars=1,resizable=1,width=' + iWidth + 
                ',height=' + iHeight);
    self.name = 'mainWin';
}

function whenExit() {
    if (bNavSafe)
        return true;
    else {
        popUp('popup.html',200,200);
        return false;
   }
}

function navTo(sURL) {
    bNavSafe = true;
    window.location = sURL;
    return true;
}
</script>

</head>

<body onunload="return whenExit();">
If you try to leave this page, a pop-up window appears.
But if you click <a 
href="javascript: navTo('http://www.allaire.com');">Move to another
page</a> you will not get the pop-up window.
</body>
</html>

Just save this file and view it in your browser.  The only drawback to this
is the fact that all of your links have to be modified to resemble the href
tag above....

Hope this helps.
____________________________________________
Julian Easterling, Senior Developer
The CDM Group -- Chevy Chase, MD  USA

"The code says what the program is doing, the remarks
(comments) say what it is supposed to be doing. 
Debugging is reconciling the differences."


-----Original Message-----
From: Sean Blenkhorn [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 13, 2000 10:45 AM
To: Fusebox
Subject: RE: pop-up on leaving my site



This example simply uses the onUnload function of the Body.  Which means
each time you change pages, the pop up window would be created.  This is not
the desired outcome.  I think the only way is with using frames and the
associated onUnload for them.

Sean

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to