fine-uploader icon indicating copy to clipboard operation
fine-uploader copied to clipboard

Feature - make beforeunload hook optional

Open rohanc opened this issue 10 years ago • 1 comments

As a consequence of including Fine Uploader in my project, the bfcache is disabled. This is because it adds a beforeunload handler. I can see it in the source around _preventLeaveInProgress. See https://developer.mozilla.org/en-US/Firefox/Releases/1.5/Using_Firefox_1.5_caching

Due to this side-effect, I would rather that the uploader added its beforeunload event only after the first file has been submitted for processing. This would be helpful in my project because only a small percentage of users use the upload feature, but they are all forced to miss out on the ability to return to a complex form using the browser Back button.

If this is not possible, an option to prevent the beforeunload handler from being added in the first place would be appreciated.

rohanc avatar Sep 25 '15 05:09 rohanc

I can see adding a new configuration option for this, such as confirmBeforeUnload with a default value of true.

In the meantime, you can turn the function that adds this handler into a NOOP with the following code:

qq.FineUploader.prototype._preventLeaveInProgress = function() {};

Make sure you do this before you construct a new instance of Fine Uploader, but after the script has loaded (of course). As with access to any underscored property, this is not part of the official API and may change at any time, but is probably a reasonable workaround for now.

I'll update this case when an option is added.

rnicholus avatar Sep 25 '15 14:09 rnicholus