当前位置:首页 > JSP教程 > JSP常见问题

javascript判断文件是否存在实例代码

 javascript判断文件是否存在

1. 客户端

<script language="javascript">
function fileexist()
{
  var sfso=new activexobject("scripting.filesystemobject");
  var fpath="[the path of the file]";
  if(sfso.fileexists(fpath))
  {
       alert("exist");
  }
  else
  {
    alert("doesn't exist");
    }
}
</script>

2. 服务器端

<script language="javascript">
function fileexist()
{
  var xmlhttp=new activexobject("microsoft.xmlhttp");
  xmlhttp.open("get",fileurl,false);
    xmlhttp.send();
    if(xmlhttp.readystate==4)
  { 
       if(xmlhttp.status==200) alert("exist"); 
       else if(xmlhttp.status==404) alert("doesn't exist");
       else alert("don't know"); 
    }
 }
</script>

 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐