Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was having the same problem, and I solved it by using a styled <code>&lt;label&gt;</code> tag with a slight workaround in Firefox.</p> <p><a href="http://jsfiddle.net/djibouti33/uP7A9/" rel="noreferrer">http://jsfiddle.net/djibouti33/uP7A9/</a></p> <p><strong>The Goals:</strong></p> <ol> <li>allow user to upload a file by using standard html file input control</li> <li>hide standard html file input control and apply own styling</li> <li>after user selects file to upload, automatically submit the form</li> </ol> <p><strong>The Browsers:</strong></p> <ul> <li>Firefox, Chrome, IE8/9, Safari</li> <li>IE7 didn't work, but it might if you add it to the workaround detailed below.</li> </ul> <p><strong>The Initial Solution:</strong></p> <ol> <li>Hide the file input by positioning it offscreen. Important not to display:none as some browsers won't like this.</li> <li>Add another styled element to the page (link, button). </li> <li>Listen for a click on that element, then programmatically send a click to the file input to trigger the native 'file explorer'</li> <li>Listen for the file input's onchange event (occurs after a user chooses their file) </li> <li>Submit the form</li> </ol> <p><strong>The Problem:</strong></p> <ol> <li>IE: if you programmatically send a click to a file input in order to activate it (2), programmatically submitting the form (5) will throw a security error</li> </ol> <p><strong>The Workaround Solution:</strong></p> <ol> <li>Same as above</li> <li>Take advantage of the accessibility features built in to the label tag (clicking on a label will activate it's associated control) by styling a label tag instead of a link/button</li> <li>Listen for the file input's onchange event</li> <li>Submit the form</li> <li>For some reason Mozilla browsers won't activate a file input by clicking on it's label. </li> <li>For Mozilla, listen for the click on the label and send a click event to the file input to activate it.</li> </ol> <p>Hope this helps! Check out the jsfiddle for details on the html/js/css used to make it all work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload