var startPoint = new Date(); var loadStartPoint = new Date(); var loadingShowed = false; //防止页面后退 history.pushState(null, null, document.URL); window.addEventListener('popstate', back_common); function back_common() { history.pushState(null, null, document.URL); } document.addEventListener('contextmenu', function (e) { e.preventDefault(); return false; }); document.addEventListener("touchstart", function (e) { e.preventDefault(); e.stopPropagation(); return false; }, false); $(function () { $(document).click(function () { resetTime(); }); jQuery.support.cors = true; var commonTimeOut = 10000; var longTimeOut = 60000; var loadingTimeout = 60000; if ($("#loading") != null) { window.setInterval(function () { if ($("#loading").is(":visible") && !loadingShowed) { loadingShowed = true; loadStartPoint = new Date; } if ($("#loading").is(":hidden") && loadingShowed) { loadingShowed = false; } }, 100); } if (location.href.indexOf("/Home/screensaver") < 0 || location.href.indexOf("/Home/screensaverTwo") >= 0) { var interRet = window.setInterval(function () { var isNotLoading = $("#loading").is(":hidden"); if ($("#loading").length > 0 && !isNotLoading) { resetTime(); } var curTime = new Date(); var timeOutVal = commonTimeOut; if (location.href.indexOf("/Home/screensaverTwo") >= 0 || location.href.indexOf("/Home/Preview") >= 0) { timeOutVal = longTimeOut; } if (parseInt(curTime - startPoint) >= timeOutVal) { $.post(rootPath + "/Home/StopCheck", null, function (res) { }); window.clearInterval(interRet); location.href = rootPath + "/Home/screensaver"; } //设置读取超时 if (parseInt(curTime - loadStartPoint) >= loadingTimeout && loadingShowed) { $.post(rootPath + "/Home/StopCheck", null, function (res) { }); window.clearInterval(interRet); location.href = rootPath + "/Home/screensaver"; } }, 1000); } }); function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } function resetTime() { startPoint = new Date(); }