传Firefox浏览器对于上传文件的安全问题,只能得到绝对路径。如果像上传图片预览,可实现如下:
注意,此处实现的思路是,IE浏览器把预览图片显示在div中,而firefox浏览器只能显示在img标签中。
function changePhoto(sender){
if(userAgent.indexOf("firefox")>=1){//fiefox浏览器
alert(sender.files[0]);
document.getElementByIdx('image0').src=sender.files[0].getAsDataURL();
}elseif(window.ActiveXObject){//IE浏览器
var newPreview = document.getElementByIdx("newPreview");
newPreview.innerHTML="";
newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")
.src=document.getElementByIdx('myFile').value;
newPreview.style.width= "120px";
newPreview.style.height = "154px";
newPreview.style.border="1px solid #a3b7cf";
}
}
页面如下:
<style type="text/css">
#newPreview
{
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
}
</style>
<div class="cl_left1" id="info2"name="info2">
<a><span>照片上传:</span><inputtype="text" class="text1" id="filename"name="filename" />
<spanclass="file"></span>
<input class="file_0" type="file" name="myFile"id="myFile" οnchange="changePhoto(this)"/>
</a>
</div>
<div id="newPreview">
<aclass="img_head" id="img_head"><imgid="image0"src="<%=path%>/<%=photo%>"<%=path%>/A3IAIo/person1.jpg'"
height="154px;"width="120px;"/>
</a>
</div>
让Firefox显示本地文件的唯一办法就是修改它的默认安全策略:
- 在Firefox的地址栏中输入“about:config”
- 继续输入“security.checkloaduri”
- 双击下面列出来的一行文字,把它的值由true改为false