Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.close ( ) event

Status
Not open for further replies.

FALCONSEYE

Programmer
Jul 30, 2004
1,158
US
is it possible to trigger an event on window.close(). something like when the user clicks on the X bar on the menu to close the browser. i did something like this before but forgot how i did.
thanks for the help in advance...
 
yup, the onUnload event. for some reason, it's not working right. i have something like

<body onunload="createRec();">

function createRec() {

in this function i call another function

}

is it because i make a call to another function ?




 
As far as I rememebr there is this weird situation with onunload, when you do something in the handler the window still procceeds with closing without stopping to wait for your function. SO you either do something fast, or your code is not going to work.
 
yup that's exactly what happens. if i throw some junky code to delay the close, then everything works. like an alert()
is there a better way of doing a delay ?
thanks
 
a quick counter would be better then an alert. At least from a users view. This one is 5 sec wait, change it to what you need.


<script language="JavaScript">
<!--
var sTargetURL = "Login.asp";
function doRedirect()
{
setTimeout( "timedRedirect()", 5000 );
}

function timedRedirect()
{
window.location.href = sTargetURL;
}
//-->
</script>
 
this is what i end up doing

function pausecomp(millis)
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); }
while(curDate-date < millis);
}

then i use
pausecomp(200)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top