'Accept' attribute of input element is not working
Asked Answered
L

4

6

I came across a browse file dialog-control tag in html and the tag was

<input id="myfile" name="myfile" type="file" accept="application/pdf"/>

but the 'accept' attribute doesn't seems to have any effect. I am using Internet Explorer 8.

Liv answered 24/3, 2010 at 4:26 Comment(0)
C
15

according to the w3schools (http://www.w3schools.com/TAGS/att_input_accept.asp), the 'accept' attribute is not properly supported by any of the major browsers. The filter inside the file browser dialog will not work.

You could use a javascript validation on the form onsubmit event to verify if the file type is correct, returning false otherwise.

Compressibility answered 25/3, 2010 at 15:22 Comment(4)
I don't see in the page how it is not supported by the major browsers.Imeldaimelida
@BehnazChangizi The question and answer are both 5+ years old, and the answer is no longer correct. Most major browsers, including IE 10+, now support accept, and it's part of the HTML5 specification.Chromosome
Still not supported properly in Dec 2015. For example, I'm trying to accept font files. I provide the following list of comma separated MIME content types to the "accept" attribute: "application/font-tdpfr,application/font-woff,application/x-font-bdf,application/x-font-ghostscript,application/x-font-linux-psf,application/x-font-otf,application/x-font-pcf,application/x-font-snf,application/x-font-ttf,application/x-font-type1". When the dialog box opens, the only items listed in the filetype dropdown are "All Files" and "WOFF File (.woff)". So it's completely broken. TTF, etc. are missing.Benito
Even just 2 years ago, the discussion was about a changing "standard" and how only one browser, Chrome, implemented support, and not even consistently. bugzilla.mozilla.org/show_bug.cgi?id=826176#c3Benito
G
1

Delimiter

HTML5 accept delimiter

I can confirm in some modern browsers that if you want the file dialog types to appear you need to use a comma as a delimiter:

<input accept="image/apng, image/jpeg, image/png" name="example" type="file" />
Gaeta answered 20/10, 2019 at 21:37 Comment(2)
Yes, accpet working when open the window and apper support types, but not validate the type fileIdonna
Delimiter worked. I was trying accept="image/*" but it was not working. accept="image/*," worked. Browser: Firefox 127.0.2Scree
G
0

It seems like browsers have trouble following the IANA specifications found here: http://www.iana.org/assignments/media-types/media-types.xhtml

In my case, the application/pkcs* media types don't work at all, while for some reason application/x-pkcs12 works in chrome and partially(.p12) in IE. Firefox seems completely oblivious.

I also found this more optimistic discussion over here. File input 'accept' attribute - is it useful?

So, the best description would be "probably unsupported for uncommon formats", and with the x-pkcs vs pkcs confusion more or less unusable in my case.

Gocart answered 7/3, 2016 at 11:26 Comment(0)
T
0

I know this is an old question, but I found that for me it was my browser cache. Once I opened in incognito it worked just fine.

Tybalt answered 12/10, 2024 at 1:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.