jason0401 发表于 2015-9-5 13:19:54

GetParamValue heartbeat

var timer;
var usingERIS=true;
var _xmlHttp=null;

function GetParamValue(name)
{
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(window.location.href))
{
      return RegExp.$2;
}
return "";
}
   
// Create XMLHttpRequest object
function getXMLHTTP() {
var xmlHttpObject=null;
try {
xmlHttpObject=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
   xmlHttpObject=new ActiveXObject("Microsoft.XMLHTTP");
} catch (oc) {
   xmlHttpObject=null;
}
}
if ((!xmlHttpObject)&&(typeof(XMLHttpRequest!="undefined")))
xmlHttpObject=new XMLHttpRequest();
return(xmlHttpObject);
}
// Send a http request
function sendHttpRequest() {
if (_xmlHttp) {
_xmlHttp.open("GET", url, true);
_xmlHttp.onreadystatechange=OnReady;
_xmlHttp.send(null);
}
}
function OnReady(){
   if ((_xmlHttp.readyState==4)&&(_xmlHttp.responseText)) {
    if (_xmlHttp.responseText.indexOf("FAIL")==0) {
   alert("The record is already locked by another user");
   window.location.href='/Web/Navigation/Welcome.aspx';   
    }
    else
   window.setTimeout("sendHeartbeat()", heartbeat_period);
   }
}
// Send heartbeat by XMLHttpRequest object
function sendHeartbeat() {
//if (enable_lock=='Y') {
if ((_xmlHttp)&&(_xmlHttp.readyState!=0))
   _xmlHttp.abort();
_xmlHttp=getXMLHTTP();
if (usingERIS==true)
   sendHttpRequest();
//}
}
// Prompt if the user is idle for too long
function promptAlive() {
var message = 'Your data entry session has been idled too long, would you like to continue?';
window.focus();
usingERIS=false;

usingERIS = confirm(message);
if (usingERIS==true) {
sendHttpRequest();
window.setTimeout("sendHeartbeat()", heartbeat_period);
resetIdleTimer();
}
else
{
   window.location.href='./Navigation/Welcome.aspx';
}
}
// Reset the timer for user idle
function resetIdleTimer() {
//if (enable_lock=='Y') {
if (timer)
   window.clearInterval(timer);
timer=window.setTimeout("promptAlive()", max_idle_time);
//}
}
页: [1]
查看完整版本: GetParamValue heartbeat