IE10中的卸载事件,无表单数据 [英] Unload event in IE10, no form data
问题描述
当用户只是关闭浏览器时,我已经挂上window.unload以将表单数据保存在紧急情况下.我通过POST使用ajax发送此邮件.这适用于IE9,Chrome等,但不适用于表单数据为空(使用GET的解决方法)的IE10.
I have window.unload hooked to save my form data in emergencies when the user just closes their browser. I send this using ajax via POST. This works in IE9, Chrome etc, but not in IE10 where the form data is empty (using GET is a workaround).
我找不到对此行为的任何引用,它是否记录在某处?
I can't find any references to this behaviour, is it documented somewhere?
推荐答案
我假设您正在使用这样的代码:
I assume, you are using code like this:
<html>
...
<body onunload="inOnUnload();">
...
,其inOnUnload()
函数的定义如下:
function inOnUnload() {
xmlhttp.open("POST", "http://some-location", /*async*/ true);
http.send(request);
}
IE10中与此相关的问题是,在文档最终被卸载之后,它似乎取消了该请求.这是在表单数据有机会离开客户端之前发生的.要在IE10的onunload
事件中发送数据,必须在XMLHttpRequest.open(...)
中使用async = false
参数.
The problem with this in IE10 is that it seems to cancel the request, after the document has finally been unloaded. This happens before the form data had a chance to leaf the client. To send data in onunload
events in IE10, you must use the async = false
parameter in XMLHttpRequest.open(...)
.
以下对我来说很好:
function inOnUnload() {
xmlhttp.open("POST", "http://some-location", /*async*/ /*!!!*/ false);
http.send(request);
}
这篇关于IE10中的卸载事件,无表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!