2012-07-10 13 views

回答

1

添加到正在處理文件上傳的表單的末尾。

$(window).bind('beforeunload', function() { 
    if ($('#fileupload').data('fileupload')._active) { 
     return 'Leaving now would abort your upload. Are you sure?'; 
    } 
}); 
+0

如果這是您的工作解決方案,請接受您自己的答案。 :) – deefour 2012-07-11 01:24:05

1

這可以通過Javascript的onbeforeunload事件來完成。

var upload_pending = false; 

// ... 

// Once upload has started, toggle the boolean flag (in something like 
// a click event on the submit button for the form with the file field, 
// making sure to toggle it back after the upload finishes 
upload_pending = true; 

// ... 

window.onbeforeunload = function (e) { 
    e = e || window.event; 

    if (!upload_pending) return; 

    // For IE<8 and Firefox prior to version 4 
    if (e) { 
    e.returnValue = 'There is a pending upload.'; 
    } 

    // For Chrome, Safari, IE8+ and Opera 12+ 
    return 'There is a pending upload.'; 
}; 
+0

謝謝Deefour,這是非常好的信息,但我認爲,我可能已經發現,需要較少的工作,因爲BlueImp文件上傳腳本上傳文件時,已經包含了活動狀態的解決方案。 – kobaltz 2012-07-10 23:12:06

相關問題