Chrome后退按钮意外终止上传流 [英] Chrome back button terminates upload stream unexpectedly

查看:355
本文介绍了Chrome后退按钮意外终止上传流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为用户提供了基于表单的文件上传(一次一个),并带有ajax更新/进度条。如果他们离开目前的上传将被取消,我想给他们一个提醒。除了Chrome(v.18),以下代码可以实现该目标。如果您在Chrome中点击后退按钮,文件上传流会立即终止,并引发 org.apache.commons.fileupload.FileUploadBase $ IOFileUploadException:处理multipart / form-data请求失败。 Stream从commons.fileupload库中意外终止

I'm providing users form-based file uploads (one at a time) with ajax updates/progress bars. I want to give them a heads up if they navigate away that any current upload will be canceled. The following code achieves that goal except in Chrome (v.18). If you click the back button in Chrome the file upload stream is immediately terminated, throwing a org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly from the commons.fileupload library.

我找不到任何特定于此问题的信息,但是有没有人知道这是我现在只需要忍受的事情?谢谢。

I couldn't find any information specific to this issue, but does anyone have any idea if this is something I'm just going to have to live with for now? Thanks.

编辑:我应该补充说,Chrome仍然会显示离开页面对话框,但此时上传已停止,因此答案不会影响它根本就没有。点击Chrome中的链接不会停止上传,并且按预期行事。

I should add that Chrome does still shows the "Leave page" dialog, but at that point the upload is already stopped so the answer won't affect it at all. Clicking a link in Chrome does not stop the upload, and behaves as expected.

window.onbeforeunload = 
    function(event) {
        if (upload_in_progress) {
            var msg = "You are uploading a file." +
              "If you leave this page the upload " +
              "will be cancelled.\n\nLeave page?";
            var event = event || window.event;
            if (event) { event.returnValue = msg; }
            return msg;
        }
    };


推荐答案

在附加到beforeunload事件的Chrome和Safari函数中,必须始终返回字符串值(消息显示给用户)。

In Chrome and Safari functions attached to beforeunload event must always return string value (message displayed to user).

这篇关于Chrome后退按钮意外终止上传流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆