blueimp ( http://blueimp.github.com/jQuery-File-Upload ) と Ruby on Rails GEM Carrierwave に基づく複数ファイルのアップロード シナリオを使用しています。私が抱えている問題は、ファイルのアップロードが完了する前に、ユーザーが Web ページから移動できることです。ファイルが現在アップロードされていて、アップロードが完了する前にユーザーがページから移動した場合、確認ダイアログを返す方法を作成しようとしています。これを達成する方法について何か考えはありますか?
2 に答える
1
ファイルのアップロードを処理するフォームの最後に追加されます。
$(window).bind('beforeunload', function () {
if ($('#fileupload').data('fileupload')._active) {
return 'Leaving now would abort your upload. Are you sure?';
}
});
于 2012-07-10T23:12:22.573 に答える
1
onbeforeunload
これは、Javascript のイベントで実行できます。
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.';
};
于 2012-07-10T22:48:08.663 に答える