accept attribute in input file is not working

2019-02-14 08:26发布

hi i came across a browse file dialog control tag in htnl .and the tag was

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

but the accept attribute doesnt seems to have any effect .iam using internetexplorer 8 browser

does it have any thing to do with the accept atribute

2条回答
放荡不羁爱自由
2楼-- · 2019-02-14 09:03

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.

查看更多
别忘想泡老子
3楼-- · 2019-02-14 09:06

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.

查看更多
登录 后发表回答