我正在使用基於blueimp(http://blueimp.github.com/jQuery-File-Upload)和Ruby on Rails GEM Carrierwave的多文件上傳方案。我遇到的問題是用戶可以在上傳文件完成之前離開網頁。我試圖創建一種方式,如果文件當前正在上傳,並且用戶在上傳完成前導航離開頁面,則應返回確認對話框。有關如何完成此任何想法?確認當用戶在頁面導航時文件正在上傳
0
A
回答
1
添加到正在處理文件上傳的表單的末尾。
$(window).bind('beforeunload', function() {
if ($('#fileupload').data('fileupload')._active) {
return 'Leaving now would abort your upload. Are you sure?';
}
});
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
相關問題
- 1. 當用戶在該頁面上時導航欄燈亮
- 2. 在配置文件頁面上不顯示導航欄 - (正確使用current_page?)
- 3. 停止頁面導航並等待用戶確認
- 4. 僅當用戶在頁面上有X個像素時摺疊導航欄
- 5. 當用戶在頁面之間導航時用戶輸入不被驗證
- 6. 如何將用戶導航到正確的頁面?
- 7. 頁面用戶控制類文件上的導航代碼
- 8. 在「確認thankyou頁面」上獲取用戶電子郵件mailchimp
- 9. 如何在頁面加載時上傳用戶上傳文件和檢索?
- 10. 當在頁面內導航時UIWebView控件
- 11. 如何確認在離開頁面導航
- 12. 防止「確認導航」對話框從頁面上彈出
- 13. 在頁面導航
- 14. VB.NET:繼續文件上傳頁面導航
- 15. 當EventHandler競賽時導航到頁面?
- 16. 在Windows Phone上使用MVVM進行ListBox頁面導航的正確方法
- 17. 在導軌中訂購確認頁面
- 18. 在ASP.NET頁面上用jQuery進行用戶確認
- 19. 添加確認頁面上傳腳本
- 20. 在用戶確認時使用jquery重定向到新頁面
- 21. Xamarin.Forms控件在Android上導航回頁面時消失
- 22. 文件上傳導致頁面掛起
- 23. 如何在未登錄時導航用戶登錄頁面
- 24. Ajax調用正在進行時的頁面導航
- 25. 如何在導航到其他頁面時顯示Primefaces確認對話框?
- 26. 阻止導航控制器導航並要求用戶確認
- 27. 使用類似Facebook的模式確認導航離開頁面?
- 28. 使用AJAX導航離開頁面的確認窗口
- 29. JSF - 創建一個通用確認頁面(動態導航)
- 30. 讓用戶在特定條件下導航到/顯示頁面
如果這是您的工作解決方案,請接受您自己的答案。 :) – deefour 2012-07-11 01:24:05