相信很多人都使用过<input type="file"/>这样的HTML控件
而firefox中不能获取file的完整的文件路径,只能得到***.jpg这样的值
这个问题的确很麻烦。
从dedecms和网上的相关搜索,终于解决了这个问题
代码贴出来,此段代码的功用是预览本地图片的。

<input name="upfile1" type="file" />
<div class="divpre" id='uploadfield1'></div>


function SeePicNew2(imgdid,f) {
if(f.value=='') return ;
var newPreview = document.getElementById(imgdid);

// 这段代码是关键,如果是FF,则f.fles为真
if (f.files) {
var filepath = f.files.item(0).getAsDataURL();
} else {
var filepath = 'file:///'+f.value.replace(/\\/g,"/").replace(/\:/,"|");
}

var image = new Image(); var ImgD = new Image();
ImgD.src = filepath;
image.src = ImgD.src; FitWidth = 150; FitHeight = 100;
if(image.width>0 && image.height>0)
{
if(image.width/image.height>= FitWidth/FitHeight)
{
if(image.width>FitWidth)
{
ImgD.width=FitWidth;
ImgD.height=(image.height*FitWidth)/image.width;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else
{
if(image.height>FitHeight)
{
ImgD.height=FitHeight;
ImgD.width=(image.width*FitHeight)/image.height;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}

newPreview.style.width = ImgD.width+"px";
newPreview.style.height = ImgD.height+"px";

if(window.navigator.userAgent.indexOf("MSIE") < 1)
{
newPreview.style.background = "url('"+ImgD.src+"') no-repeat";
}
else
{
newPreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ImgD.src+"',sizingMethod='scale')";
}

ImgD = image = null;
//newPreview.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = f.value;
}

相关文章:

  • 2021-12-08
  • 2021-10-07
  • 2021-10-22
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-12
  • 2021-08-18
  • 2022-12-23
  • 2022-01-08
相关资源
相似解决方案