天天看點

根據位址判斷指定檔案是否存在

//==========================判斷指定檔案是否存在===============================開始
//判斷浏覽器  
var xmlHttp = null;
function createXMLHttpRequest() {
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest(); //Firefox,Netscape,Chrome,Safari等浏覽器
    }
    else if (window.ActiveXObject) { //IE浏覽器  
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //建立xmlHttp對象  
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //建立xmlHttp對象  
            }
            catch (e) { }
        }
    }
}
function GetURL(url) {
    createXMLHttpRequest();
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
                return true; //存在
            } else {
                return false; //不在
            }
        }
    }
}
//==========================判斷指定檔案是否存在===============================結束
           

繼續閱讀