我有一个会话超时脚本,现在已成功运行在我的网站上。该脚本来自http://www.jensbits.com/2010/04/18/coldfusion-session-timeout-with-warning-and-session-refresh/
突然间,它抛出了以下错误:
未捕获错误:在初始化之前无法调用对话框上的方法;尝试调用方法'打开
这是我的剧本:
<script type="text/javascript" language="javascript">
$(function(){
// jQuery UI Dialog
$('#dialogWarning').dialog({
autoOpen: false,
width: 400,
modal: true,
resizable: false,
buttons: {
"Restart Session": function() {
//reset session on server
$.post("restart_session.cfm");
//reset the variables
requestTime = new Date();
warningStarted = false;
countdownTime = warning;
//clear current checkSessionTimeEvent and start a new one
clearInterval(checkSessionTimeEvent);
checkSessionTimeEvent = "";
checkSessionTimeEvent = setInterval("checkSessionTime(requestTime)",warning*1000);
$('#dialogWarning').dialog('close');
}
}
});
$('#dialogExpired').dialog({
autoOpen: false,
width: 400,
modal: true,
resizable: false,
close: function() {
window.location="https://<cfoutput>#subscriber.hostName#.#subscriber.baseURL#</cfoutput>/serviceticket/index.cfm?error=2";
},
buttons: {
"Login": function() {
window.location="https://<cfoutput>#subscriber.hostName#.#subscriber.baseURL#</cfoutput>/serviceticket/index.cfm?error=2"; }
}
});
});
//Your timing variables in number of seconds
//total length of session in seconds 5400 - 1800
var sessionLength = 60;
//time warning shown (10 = warning box shown 10 seconds before session starts) 180
var warning = 10;
//time redirect forced (10 = redirect forced 10 seconds after session ends) 0
var forceRedirect = 0;
$(document).ready(function() {
//event to check session time left (times 1000 to convert seconds to milliseconds)
checkSessionTimeEvent = setInterval("checkSessionTime(requestTime)",warning*1000);
});
//event to check session time variable declaration
var checkSessionTimeEvent = "";
//time session started
var requestTime = new Date();
//initial set of number of seconds to count down from for countdown ticker (10,9,8,7...you get the idea)
var countdownTime = warning;
//create event to start/stop countdownTicker
var countdownTickerEvent = "";
//initially set to false. if true - warning dialog open; countdown underway
var warningStarted = false;
function checkSessionTime(reqTime)
{
//get time now
var timeNow = new Date();
//clear any countdownTickerEvents that may be running
clearInterval(countdownTickerEvent);
//difference between time now and time session started variable declartion
var timeDifference = 0;
//session timeout length
var timeoutLength = sessionLength*1000;
//set time for first warning, ten seconds before session expires
var warningTime = timeoutLength - (warning*1000);
//force redirect to log in page length (session timeout plus 10 seconds)
var forceRedirectLength = timeoutLength + (forceRedirect*1000);
timeDifference = timeNow - reqTime;
if (timeDifference > warningTime && warningStarted === false)
{
//reset number of seconds to count down from for countdown ticker
countdownTime = warning;
//call now for initial dialog box text (time left until session timeout)
countdownTicker();
//set as interval event to countdown seconds to session timeout
countdownTickerEvent = setInterval("countdownTicker()", 1000);
$('#dialogWarning').dialog('open');
warningStarted = true;
}
else if (timeDifference > timeoutLength)
{
//close warning dialog box if open
if ($('#dialogWarning').dialog('isOpen')) $('#dialogWarning').dialog('close');
$('#dialogExpired').dialog('open');
}
if (timeDifference > forceRedirectLength)
{
//clear (stop) checksession event
clearInterval(checkSessionTimeEvent);
//force relocation
window.location="https://<cfoutput>#subscriber.hostName#.#subscriber.baseURL#</cfoutput>/serviceticket/index.cfm?error=2"; }
}
function countdownTicker()
{
//put countdown time left in dialog box for 10, 9, 8...
$("span#dialogText-warning").html(countdownTime);
//decrement countdownTime
countdownTime--;
}
</script>
我正在运行以下JQuery版本:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.0/jquery.mobile.min.css" />
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
答案 0 :(得分:0)
我有类似的问题。它始于jQuery 1.11.0。回滚到jQuery v1.8.2并解决问题