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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form submitted intermittently upon window close in IE

Status
Not open for further replies.

pdppdpdd

Programmer
Joined
Mar 9, 2006
Messages
4
Location
US
I have code in place to catch the window close event. At window close time I want to submit a hidden form that I update during the session. The updating is working flawlessly. The call to submit() within onbeforeclose() works on most browsers except, of course, IE running on 2000/XP. Sometimes IE makes the form submission before closing the window and sometimes not. If I add an alert message after the call to the submit() method (see code below), IE always makes the form submission. It is almost as if the form object is sometimes destroyed before it can be submitted.

Has anyone ever run into this problem? Using a modal alert message to pause the window close long enough to submit the form is not an option available to me. Is there a way to verify that the form has been submitted before allowing the window close operation to continue?

code follows:
<script language="JavaScript">
<!--

window.onbeforeunload = unload_handler;

function unload_handler()
{
var frm = document.getElementById("FORM1");

frm.KEY.value = "key value";
frm.DATA.value = "data value";

frm.action = "accessCustomData.jrun?ACTION=storeQuiet";
frm.submit();

}

//-->
</script>

<form id="FORM1" name="FORM1" method="post" style="height:0px;display:none;" target="invisibleFrame">
<input type="hidden" name="KEY" value="">
<input type="hidden" name="DATA" value="">
</form>
 
No matter what you do, you will [!]never[/!] be able to stop the user from closing their browser window.

You can pick up on a close event, but you cannot stop it once it has started, AFAIK.

Good thing too, IMHO, although with the advent of popup blockers, less of a necesssity.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I am not trying to keep the user from closing the window. I just want the form to submit before the window closes.
 
Um, I don't get it. Are you saying that it cannot be done?
 
It clarifies several things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top