admin管理员组文章数量:1426620
I have a html input type file control. When I select a file with very big name, it shows plete filename in firefox which causes bad UI. Is there any solution for this problem like changing name etc?
I have a html input type file control. When I select a file with very big name, it shows plete filename in firefox which causes bad UI. Is there any solution for this problem like changing name etc?
Share Improve this question asked Jul 15, 2013 at 5:32 PopeyePopeye 1,5583 gold badges30 silver badges42 bronze badges 02 Answers
Reset to default 3You can handle it this way:
- Make your html
input file
control hidden and addonchange
event handler to change selected file name - Add a readonly html
textbox
control for showing changed file name - Add html
button
control withonclick
event handler to trigger file control's click event
DEMO here
HTML:
<input type="text" id="txtFile" readonly="true" />
<input type="button" id="btn" value="Browse..." onclick="browseFile();" />
<input type="file" id="file1" name="file1" onchange="setFileName(this.value);" />
CSS:
#file1 {
display: none;
}
JS:
function browseFile() {
document.getElementById('file1').click();
}
function setFileName(fileName) {
/* Manipulate file name here */
fileName = fileName.substr(0, fileName.lastIndexOf('.'));
document.getElementById('txtFile').value = fileName;
}
There is three possible answers I know:
- You can style size of your input, and then browser cut longer names to given size (with '...' at the end of visible part).
- You can not change from script the value of file input for security reason. The same is with trigger its click event. So the answer in this case is No.
- You can cover whole file input with "pseude custom css". It is not real input styling but uses some trick with opacity. Look here for more details.
本文标签: javascriptmanipulate html input type file filename in firefoxStack Overflow
版权声明:本文标题:javascript - manipulate html input type file filename in firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745481473a2660192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论