我提供用戶基於表單的文件上傳(一次一個)與AJAX更新/進度欄。如果他們離開目前的上傳將被取消,我想給他們一個提醒。除了Chrome(v.18),以下代碼可以實現該目標。如果您在Chrome中點擊後退按鈕,文件上傳流會立即終止,並從commons.fileupload庫中拋出org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
。鉻後退按鈕意外終止上傳流
我找不到任何特定於此問題的信息,但是有沒有人有任何想法,如果這是我現在只需要忍受的事情?謝謝。
編輯:我應該補充一點,Chrome仍然顯示「離開頁面」對話框,但此時上傳已停止,因此答案根本不會影響它。點擊Chrome中的鏈接不會停止上傳,並且按預期行事。
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;
}
};
點擊鏈接...不停止上傳? – gengkev 2012-04-21 19:23:08
沒有。我得到對話框,並可以按預期保持/離開頁面,除非我選擇離開頁面,否則繼續。 – randall 2012-04-22 00:43:05