美文网首页
js 根据路径判断文件是否存在

js 根据路径判断文件是否存在

作者: _嘿嘿_ | 来源:发表于2019-01-10 10:26 被阅读0次

    IsExstsFile(yourFileURL) {
    var flag;
    var xmlhttp;
    if(window.XMLHttpRequest)
    {
    xmlhttp = new XMLHttpRequest();//其他浏览器
    }
    else if (window.ActiveXObject)
    {
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");//旧版IE
    }
    catch (e) { }
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//新版IE
    }
    catch (e) { }
    if (!xmlhttp) {
    window.alert("不能创建XMLHttpRequest对象");
    }
    }
    xmlhttp.open("GET",yourFileURL,false);
    xmlhttp.send();
    if(xmlhttp.readyState==4){
    if(xmlhttp.status==200)
    flag =true;
    else
    flag =false;
    }
    return flag;
    },

    相关文章

      网友评论

          本文标题:js 根据路径判断文件是否存在

          本文链接:https://www.haomeiwen.com/subject/vlporqtx.html