现在的位置: 首页 > 综合 > 正文

如何用JavaScript检查一个URL是否有效?

2013年07月09日 ⁄ 综合 ⁄ 共 542字 ⁄ 字号 评论关闭
<!--
Author: δCat
Date: 2006-1-18
Remarks: For AQ ON 'BaiDu Know'
-->
<html>
<head>
<title>Super Detector</title>
<meta name="Author" content="δCat">
<script language="javascript">
<!--//
function doTest(vUrl)
{
if (vUrl == "")
{
alert("指定WEB地址!");
}
else
{
var x = new ActiveXObject("Microsoft.XMLHTTP");
x.Open("HEAD", vUrl, false);
x.send();
if (x.status == 200)
{
alert("地址有效!");
}
else
{
alert("地址无效");
}
x = null;
delete x;
}
}
//-->
</script>
</head>
<body>
<div align="center">
<input type="text" name="url" id="url"> <input type="button" value="Test The Url" onclick="doTest(url.value);">
</div>
</body>
</html> 

抱歉!评论已关闭.