HTML - File Upload Button and Odd Text Cursor Behavior in IE - Stack Overflow PDF
HTML - File Upload Button and Odd Text Cursor Behavior in IE - Stack Overflow PDF
x Dismiss
Sign up
I've built an upload button that's formatted to look like your typical html button, instead of the browser standard file upload form. The approach
was to style an anchor element and overlay a transparent file input element on top.
This approach works fine in all browsers but IE. In IE, when the user clicks the upload button a text cursor appears as if the user had clicked
on a text input box. The user can trigger the file upload dialog by double clicking the button. But this isn't the behavior we want or that anyone
expects.
I'm at a loss as to why this is happening. I've set up a jsfiddle demonstrating the issue here: http://jsfiddle.net/davelee/yfSmc/3/
what version(s) of IE are you testing with? Spudley May 17 '12 at 20:49
it's because <input type="file />" is different browser to browser. When you try to put something on top
of it, you're actually clicking the text field Adam Sweeney May 17 '12 at 20:49
This happens in IE8 and IE9. Dave Lee May 17 '12 at 20:50
This link provides a working example for all browsers (right back to Netscape 4):
quirksmode.org/dom/inputfile.html Spudley May 17 '12 at 20:54
Maybe instead of using the default file upload dialog input you just use JavaScript to prompt the dialog to
open on click. Check this thread out. stackoverflow.com/questions/6292825/ Kris Hollenbeck May 17 '12
at 20:55
5 Answers
I have just worked on this exact issue. With IE, yes, there is a small area on the left of the
button that acts as a text input (for the file name to be entered manually). The solution that I
figured out was to increase the font-size of the input field. Strange, I know, but by increasing
the font-size, you increase the "Browse..." button portion of their input field, and therefore
increase the clickable area and push out the text portion of their upload button. Since the
button is transparent anyway, nobody is the wiser :)
Thanks, this is all that was needed in my case, perfect! Elise Oct 4 '13 at 13:13
https://stackoverflow.com/questions/10643270/file-upload-button-and-odd-text-cursor-behavior-in-ie Page 1 of 3
html - File upload button and odd text cursor behavior in IE - Stack Overflow 5/30/17, 5)26 PM
Setting the width and height of the file input element fixes the issue in both ie8 and ie9.
http://jsfiddle.net/davelee/yfSmc/4/
Take a outer div to that input file apply over flow hidden and width to it, then to the input file
apply some css like: font-size, margin-left in negative.
<div class="outerWrap">
<input type="file" id="fileUpload"/>
</div>
.outerWrap {
width: 200px;
height: 50px;
overflow: hidden;
}
#fileUpload {
width: 210px;
height: 50px;
margin-left: -10px;
font-size: 70px;
}
for reference got this link: http://jsfiddle.net/TrdJ8/ and try it out on IE-9
z-index
lowest element
z-index:1
highest
z-index:2;
https://stackoverflow.com/questions/10643270/file-upload-button-and-odd-text-cursor-behavior-in-ie Page 2 of 3
html - File upload button and odd text cursor behavior in IE - Stack Overflow 5/30/17, 5)26 PM
Rob Sedgwick
4,337 3 9 30
https://stackoverflow.com/questions/10643270/file-upload-button-and-odd-text-cursor-behavior-in-ie Page 3 of 3