var file1= document.getElementById("file1").value;
// 判断浏览器类型,防止浏览器将文件路径设为C:/fakepath/
var isIE = (document.all) ? true : false;
var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);
if(isIE7 || isIE8)
{
var file = document.getElementById("file1");
file.select();
file1= document.selection.createRange().text;
document.selection.empty();
}
本文介绍了一种方法,用于在Internet Explorer 7和8中获取用户选择文件的真实路径,避免了浏览器默认提供的C:/fakepath/问题。此技巧通过检测浏览器类型并使用特定于IE的方法来实现。
7451

被折叠的 条评论
为什么被折叠?



