在打开这个链接之前用XMLHTTP的方式判断一下这个链接是否存在再加打开:<script language="javascript">
function getURL(url)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",url,false);
xmlhttp.send();
if (xmlhttp.readyState==4) return xmlhttp.Status==200;
return false;
}alert(getURL("http://www.csdn.net/"));
alert(getURL("http://www.csdn.net/aa.asp"));
</script>
function getURL(url)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",url,false);
xmlhttp.send();
if (xmlhttp.readyState==4) return xmlhttp.Status==200;
return false;
}alert(getURL("http://www.csdn.net/"));
alert(getURL("http://www.csdn.net/aa.asp"));
</script>
<script language="javascript">
function getURL(url)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",url,false);
xmlhttp.send();
if (xmlhttp.readyState==4) return xmlhttp.Status==200;
return false;
}
function mm(e, url)
{
if(!getURL(e.href)) e.href = url;
}
</script>