Skip to content Skip to sidebar Skip to footer

Html File Drag and Drop Upload Stackoverflow

How to correctly utilize preventDefault(), stopPropagation(), or return simulated; on events

preventDefault(), stopPropagation(), and return false; are non interchangeable, nor are they tools of trial-and-fault.

Paradigm courtesy of FineUploader
  1. An input to handle the file upload dialog. This is hidden (display: none;) , as we will be triggering the upload dialog using the following 2 elements.
  2. A div with the grade of file-upload__dropzone which acts as the main 'drib zone' where we will be able to elevate-and-drop files (lawmaking not included) or click to open a file upload dialog.
  3. An a tag with the class of file-upload__btn--upload which volition deed every bit the "Upload files" button, which when clicked will open a file upload dialog.
  1. A fileUpload part to trigger the click effect on the file upload input.
  2. Assigning both the dropzone div and a push to variables.
  3. Adding result listeners to those, which when clicked invoke the fileUpload function.

upshot.preventDefault()

consequence.stopPropagation()

return false;

Nonetheless…

  1. Preventing the default behaviour — navigating the browser to the a tag's href aspect.
  2. Stopping any event propagation — stopping the click effect from bubbling up the DOM.

Determination

robinsonwirave1956.blogspot.com

Source: https://medium.com/@jacobwarduk/how-to-correctly-use-preventdefault-stoppropagation-or-return-false-on-events-6c4e3f31aedb

إرسال تعليق for "Html File Drag and Drop Upload Stackoverflow"