IE8 javscript上传文件出现 fakepath 的解决方法
IE8的安全性有所改动,用JavaScript预览本地图片的功能失效了,真实的路径被C:\fakepath\ 取代了,原来是因为IE8增加了安全选项,默认情况下不显示上传文件的真实路径,进入internet选项,修改下设置即可显示真实的文件路径。
附带不用修改浏览器安全配置的javascript代码,兼容ie, firefox全系列
function getPath(obj)
{
if(obj)
{
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
if(obj.files)
{
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
参数obj为input file对象
document.selection 介绍
document.selection 表示当前网页中的选中内容。
方法有:
* clear 清除选中的内容
* empty 取消选中
* createRange 返回 TextRange 或 ControlRange 对象
* createRangeCollection 不支持
属性有:
* type 选中内容的类型
* typeDetail 不支持
原文链接:http://www.hackline.net/a/school/xtrm/2010/0226/2685.html
版权声明:
作者:Kiyo
链接:https://www.wkiyo.cn/html/2010-05/i630.html
来源:Kiyo's space
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论