js 判断文件是否存在

来源:互联网 发布:淘宝随便逛逛 编辑:程序博客网 时间:2024/05/18 07:18

判断客户端文件时,可以用

复制代码
var fso=new ActiveXObject("Scripting.FileSystemObject");if(fso.FileExists(encodeURI(path)))
{
return true;
}else
{return false;}
复制代码

 


判断服务器端(网络文件)时,可以用

复制代码
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open("GET",encodeURI(path),false);xmlhttp.send();if(xmlhttp.readyState==4)
{ if(xmlhttp.status==200)
 {
return true;
}
else {
return false;
}} 
原创粉丝点击