js判斷本地文件是否存在


方法一:
//判斷文件是否存在
    function IsExstsFile(filespec) {
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        if (fso.FileExists(filespec))
            return true;
        else
            return false;
    }
 
 
方法二: (加載ActiveXobject容易出現權限錯誤!)
function  test() {
var  fileURL =  "" //文件路徑(相對路徑)
var  xmlhttp= new  ActiveXObject( "Microsoft.XMLHTTP" );
xmlhttp.open( "GET" ,fileURL, false );
xmlhttp.send()();
if (xmlhttp.readyState==4){   
if (xmlhttp.status==200)  return  true //存在
else  if (xmlhttp.status==404)   return  false //不存在  
else  alert( "Error" );  //報錯
//其他狀態   
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM