<script>
function CheckPage(url)
{
var h = new ActiveXObject("Microsoft.XMLHTTP")
h.open("HEAD",url,false)
h.send()
return h.status==200
}
if(CheckPage("http://community.csdn.net/Expert/topic/3331/3331784.xml?temp=.9480402"))
alert("存在")
else
alert("不存在")
</script>
function CheckPage(url)
{
var h = new ActiveXObject("Microsoft.XMLHTTP")
h.open("HEAD",url,false)
h.send()
return h.status==200
}
if(CheckPage("http://community.csdn.net/Expert/topic/3331/3331784.xml?temp=.9480402"))
alert("存在")
else
alert("不存在")
</script>
function getURL(url)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",url,false);
xmlhttp.send();
if (xmlhttp.readyState==4)
alert((xmlhttp.Status==200)?"存在":"不存在");
}
//user like this:
getURL("http://community.csdn.net/Expert/topic/3331/3331784.xml?temp=.8093073")
</script>
把net_lover(孟子E章)写的CheckPage()加进去。
然后在你的代码里这样调用就行了:
function LoadData(form)
{
var s;
s="HistorySpread"+form.year.value+form.mon.value+".htm";
if(CheckPage(s))
{
parent.framedown.location.href=s;
}
else
{
parent.framedown.location.href="error.htm";
}
}
<head>
<script type="text/javascript">
function CheckPage(url)
{
var h = new ActiveXObject("Microsoft.XMLHTTP");
h.open("HEAD",url,false);
h.send();
return h.status==200 ;
}function go()
{
alert(CheckPage('http://www.heroworld.net/heroes3site/index.htm'));
}
</script>
<body >
<input type="button" value="alert" onclick="go()">
</body>
</html>我用上面的代码测试了http://www.heroworld.net/heroes3site/index.htm 这个页面
是好的啊?
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
function LoadData(form) {
var s;
s="HistorySpread"+form.year.value+form.mon.value+".htm";
res=CheckPage(s);if(res==false)
{
parent.mainFrame.location.href="error.htm";
}
else
{
parent.mainFrame.location.href=s;
}
}function CheckPage(url)
{
var h = new ActiveXObject("Microsoft.XMLHTTP");
h.open("HEAD",url,false);
h.send();
return h.status==200;
}//-->
</script>
</head>
<!--两个下拉框显示年和月-->
<body bgcolor="#646F95">
<form action="" name="form1" target="_self">
<table width="75%" border="0" align="left">
<tr>
<td width="2%" height="23" nowrap> <div align="left"></div></td>
<td width="22%" nowrap> <div align="left">
<select name="mon">
<option value="01">Jan.</option>
<option value="02">Feb.</option>
<option value="03">Mar.</option>
<option value="04">Apr.</option>
<option value="05">May.</option>
<option value="06">Jun.</option>
<option value="07">Jul.</option>
<option value="08">Aug.</option>
<option value="09">Sep.</option>
<option value="10">Oct.</option>
<option value="11">Nov.</option>
<option value="12">Dec.</option>
</select>
<select name="year">
<option value="2003" selected>2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</div></td>
<td width="76%" nowrap> <div align="left">
<input type="button" name="Button" value="DATA QUERY" onClick="LoadData(this.form)">
</div></td>
</tr>
</table>
</form>
</body>
</html>但是现在不管什么页面都显示不了了,到底怎么回事呢?救我
改为:
var name="www.xx.com/"; //name为你保存页面的域名 如www.csdn.net/
var path="xx"; //xx为你保存页面的文件夹名
s="http://"+ name + path + "HistorySpread"+form.year.value+form.mon.value+".htm";
好像是因为上面测试文件存在的方法不能直接测试当前文件夹中的页面。
所以需要完整的URL。另外parent.mainFrame.location.href="error.htm";
parent.mainFrame.location.href=s;
这两句也有问题。改成location="error.htm";及location=s;我用上面改后的方法测试你的代码成功了。
var path="xx/";