Sometimes data of form can't be sent in onbeforeunload event handler

RESOLVED DUPLICATE of bug 560767

Status

()

defect
RESOLVED DUPLICATE of bug 560767
8 years ago
6 years ago

People

(Reporter: promo.ivan21, Unassigned)

Tracking

4.0 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Reporter

Description

8 years ago
User-Agent:       Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0
Build Identifier: Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0

Create handler on onbeforeunload event. This handler calls submit function of form at the end handler. Sometimes the form's data can't be sent.
It works correctly in FF 3.6, Google Chrome, IE

Reproducible: Sometimes

Steps to Reproduce:
1. In body tag to add onbeforeunload event handler
2. In the event handler to fill form then call submit function of this form
Actual Results:  
Sometimes data is not sent.

Expected Results:  
Always data should be sended

My the event handler looks like:

function onUnload() {
    var sessionId = document.getElementById('${application}').getSessionId();
    var globalConnectionName = document.getElementById('${application}').getConnectionName();

    if (sessionId == null)
        return;

    logoutForm.session.value = sessionId;
    logoutForm.connection_name.value = globalConnectionName;
    logoutForm.time.value = new Date().getTime();
    logoutForm.submit();
}
Reporter

Updated

8 years ago
Summary: Sometimes form's data can't be sent in onbeforeunload event handler → Sometimes data of form can't be sent in onbeforeunload event handler
Version: unspecified → 4.0 Branch

Comment 1

8 years ago
I have the same problem. I let the user choose saving the data in this event but fail. With Firebug help, found out the form is not submitted totally. This happens in FF4.0.1 on XP/Linux. My code works in IE8 and FF3.6.17.

Comment 2

8 years ago
missed one thing: after submit a form, if alert any message, like "data are sent to save", the form can be submitted and data are saved. seems FF4 goes right away after executing submit() function. At first, I thought maybe it is too fast after submit() func to make it fails to send out the form. So I tried to delay 2-5 seconds (setTimeout("1=1;", 2/5000)) after submit() function ,simulating alert affect, but failed. Thus it is a time problem. Maybe it is bubble problem: FF executes submit() function but fails to catch it?!

Comment 3

8 years ago
now I use ajax to save the data. Don't forget to set its async property with false. If Async=true, it doesn't work, too. Hope this can help someone.

Comment 4

6 years ago
I think this is expected behaviour, at least in the way that you should not depend on onbeforeunload to execute reliably, especially for outgoing connections. I'd rather try to store data on beforeunload in localStorage, or better, periodically (or input[onchange]) before any unload happens. 

So I'd WONTFIX this bug though iirc this is only something peers should do/decide.

Comment 5

6 years ago
Actually, I'm just going to duplicate this to Bug 560767 which aims to block any navigation/redirection in onbeforeunload (which this bug should fall into).
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 560767
You need to log in before you can comment on or make changes to this bug.