在IE9下,本地图片预览都无法正常显示,经过测试发现,原因在于IE9下无法获取file控件的文件路径。以前的代码如下:var strPic = fileImg.value;if ($.ie && $.browser.version > 6) {
fileImg.select();
strPic = document.selection.createRange().text;
document.selection.empty();}如果strPic不为空,则使用滤镜预览。以上代码在IE 6 7 8均正常使用,在IE9下,document.selection.createRange()拒绝访问,看来安全性有所提高。最后测试发现,在IE9下,如果file控件获得焦点,则document.selection.createRange()拒绝访问,因此,只需要在fileImg.select()后面加一句fileImg.blur()即可。
fileImg.select();
strPic = document.selection.createRange().text;
document.selection.empty();}如果strPic不为空,则使用滤镜预览。以上代码在IE 6 7 8均正常使用,在IE9下,document.selection.createRange()拒绝访问,看来安全性有所提高。最后测试发现,在IE9下,如果file控件获得焦点,则document.selection.createRange()拒绝访问,因此,只需要在fileImg.select()后面加一句fileImg.blur()即可。
function getValue(obj)
{
if (version.substr(version.indexOf("MSIE") + 5, 1) >= 9) {
var strPic = obj.value;
obj.select();
obj.blur();
strPic = document.selection.createRange().text;
return strPic;
}
}
所谓的obj就是file。