I have a button
to upload images in my web project; in Chrome and Microsoft Edge it works, but in Firefox it doesn't. Clicking it should open the window to search for the image to upload as it does in other browsers.
My HTML code:
<button data-upgraded=",MaterialButton" class="mdl-button mdl-js-button mdl-button--icon mdl-button--colored f-left">
<i class="material-icons ">cloud_upload</i>
<form method="POST" action="http://timeline.dev/post/ajaxupload" accept-charset="UTF-8" class="x-uploader" enctype="multipart/form-data">
<input name="_token" value="3kpNrTDVx59bdv1KqB8x4HNbftxdDC1TpIjpNgeX" type="hidden">
<input name="file" type="file">
</form>
</button>
That code should work the same as it does in Chrome and Explorer:
This is a problem that occurs because the HTML code is invalid. In the HTML definition it is indicated that the content inside a button can be:
That is, phrase-type content, but not interactive. And within interactive content includes (but is not limited to):
a
,button
,select
orinput
other thanhidden
(emphasis added by me):In your code you include a
form
and ainput
of typefile
inside abutton
which makes the code invalid, so each browser will interpret it however it can. Chrome and IE interpret it in a way you like and Firefox in a way you don't... but it could be another way.One way to fix the problem is to make the code valid:
id
to the file input, andbutton
to alabel
that points to theinput
(with afor
).So the code will be valid and works in all browsers: