if clients' ActiveX security settings are low enough, use FileExists method in Scripting.FileSystemObject:var fso = new ActiveXObject('Scripting.FileSystemObject');
alert(fso.FileExists('C:/path/fileName.html'));
alert(fso.FileExists('C:/path/fileName.html'));
you can use xmlhttp to do this,but make sure in the same domain.var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("GET",yourFileURL,false)
xmlhttp.send()
if(404 == xmlhttp.status){
alert("the file is not found...")
}
---------------------------------------------
网事随风
QQ:241284
<SCRIPT>
function add()
{
var ress=document.forms[0].code.value
window.location="view-source:"+ress;
}
</SCRIPT><br>
输入要查看源代码的URL地址:
<FORM>
<input type="text" name="code" size=28 value="Http://">
<input type="button" value="查看" onClick=add()>
<input type="reset" value="清除">
</FORM>
<br>输入要查找的文件名及其路径:<br>
<FORM method="post" action="oFile.asp">
文件名: <input type="text" size= 25 name="need">
<input type="submit" value="查找">
</FORM><IMG id="oFile" dynsrc="<%=Request("need")%>">
<SCRIPT language="jscript" defer>
setTimeout(
function (){
alert(
oFile.fileSize>-1 ?
"\n"+
"发现目标文件!\n\n"+
"文件大小:"+oFile.fileSize+"字节\n\n"+
"创建日期:"+oFile.fileCreatedDate+"\n\n"+
"修改日期:"+oFile.fileModifiedDate+"\n\n"+
"更新日期:"+oFile.fileUpdatedDate+"\n\n"
: "此文件不存在 !"
);
},
250
)
</SCRIPT>
<SCRIPT>
function add()
{
var ress=document.forms[0].code.value
window.location="view-source:"+ress;
}
</SCRIPT><br>
输入要查看源代码的URL地址:
<FORM>
<input type="text" name="code" size=28 value="Http://">
<input type="button" value="查看" onClick=add()>
<input type="reset" value="清除">
</FORM>
<br>
function ReportFileStatus(filespec)
{
var fso, s = filespec;
fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(filespec))
s += " exists.";
else
s += " doesn't exist.";
return(s);
}
[VBScript]
Function ReportFileStatus(filespec)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
ReportFileStatus = msg
End Function
够用了吧?