JavaScript 判断文件是否存在
1. 客户端 //主要针对本地IE浏览器访问
<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.
服务器端//远程浏览器访问和本地Firefox访问
<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>
或者
<script language="JavaScript">
function fileExists(file)
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}
else if(window.ActiveXObject)
{
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
 
相关文档:
a href="javascript:if(confirm(
悬赏分:0 - 解决时间:2008-9-25 13:58
a href="javascript:if(confirm('http://hunter.51rc.com/ \n\n文件并未依 Teleport Pro 取回,因为 它的域或路径超过开始网址中设置的范围。 \n\n你要从服务器上打开它吗?'))window.location='http://hunter.51rc.com/'" tppabs="http://h ......
简单的例子,自己看看,省得以后老是去找了。
<script language="javascript">
//用正则替换将X替换成y
var s="daxdasx";//原字符串
var k="x";//被替换的字段
var re = new RegExp(k,"g");
alert("替换前字符串为:"+s);
s = s.replace(re,"y");
alert("替换后字符串为:"+s);
</script> ......
Javascript 面向对象机制的实现
自定义类的实现方法很多,重点谈两种。
构造函数法
function Player(url){
this.url = url;
this.showUrl = function(){
alert(this.url);
}
&nb ......
JavaScript常用验证函数
引自:http://www.webdeveloping.cn/blog/?action=show&id=209
//校验是否全由数字组成
function isDigit(s) {
var patrn=/^[0-9]{1,20}$/;
i ......
一段JavaScript脚本程序,负责关闭窗口,如果网页不是通过脚本程序打开的(window.open()),调用window.close()脚本关闭窗口前,必须先将window.opener对象置为null,否则浏览器(IE7、IE8)会弹出一个确定关闭的对话框。
<script language="javaScript">
function closeWindow()
{
window.opener = null;
w ......