一、判斷鏈接有效的jsp頁HttpURLVerify.jsp
- 功能函數包括:鏈接的有效性判斷,郵件通知,短信通知,日值記錄等
- 注意:該頁最好用線程來處理,否則可能影響調用頁用戶單擊事件的訪問速度
二、調用HttpURLVerify.jsp頁的javascript函數(加入需要檢測的網頁的<head>和</head>之間):
<SCRIPT language=JavaScript>
function Aclick(){
if ("A"==event.srcElement.tagName.toUpperCase()) {
var url = event.srcElement.getAttribute("href");
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var post="url="+url;//構造要攜帶的數據
xmlhttp.open("POST","http://localhost/HttpURLVerify.jsp",false);//使用POST方法打開一個到服務器的連接,以異步方式通信
xmlhttp.setrequestheader("content-length",post.length);
xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded");
xmlhttp.send(post);//發送數據
var res = xmlhttp.responseText;//接收服務器返回的數據
if(res==1){
alert("該鏈接暫時無效,已經報告給管理員了");
window.status="鏈接無效"
return false;
}else{
window.status="鏈接有效"
}
}
}
document.οnclick=Aclick;
</script>