Web Development

General discussion


Trapping the 'close' box in IE 6

By michaelbaran ·
While working on a web application for my job, I've run across the need to try to keep my potential end users from prematurly exiting the application by clicking on the standard 'Close' button in IE (that 'X' button in the upper right of every Windows app.).

So far I've been using the onBeforeUnLoad method of IE and a variable set when the page loads to allow valid links off the page to function as usual but display an alert if the user clicks the close button.

var allowclose = false;

function window_onbeforeunload() {
if (! allowclose) {
alert ("You cannot close this window - The system is processing. Please wait until the window closes itself.")
return "You don't want to do this";

The problem I'm running into is that when I click on an anchor link within the page, it fires the onBeforeUnload before executing the function I've stashed after the javascript:void bit in my link's HREF property.

<a href="javascript:void loadNewPage('...stuff...');" onmouseover="window.status=''; return true;" class="pageLink">...Stuff...</a>

So whenever I click on a link on my page, I get the same "Are you sure you want to do this" message that I only want to appear when the user clicks on the 'Close' box. Any suggestions on how I can get around this problem?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Did you try...

by shelleydoll In reply to Trapping the 'close' box ...

What happens when you make your links open to a new window? (set target in the anchor).

<a href="javascript:void loadNewPage('...stuff...');" onmouseover="window.status=''; return true;" class="pageLink" target="_new">...Stuff...</a>

Related Discussions

Related Forums