【发布时间】:2010-09-02 14:25:24
【问题描述】:
我有一个我写的 Jquery 函数,它在一定量的不活动后使屏幕变黑,创建一个弹出窗口,允许用户单击一个按钮以保持登录状态,然后将它们注销(关闭应用程序窗口),如果他们没有及时响应。
环境是 ASP.NET (VB)。从技术上讲,我们不使用母版页,但我们确实有一个父页面,其中包含我们的页眉、页脚和导航,并且我的 Jquery 代码从该窗口调用,通过 IFrame 加载。
我的问题是,如果在子窗口中工作,父窗口无法识别系统正在使用,并会在分配的时间自动参与。
我已经在阳光下尝试了所有我能想到的东西,但没有任何东西能正常工作。我的事件处理程序正在工作,它确实调用了父窗口函数,但计时器没有被重置。
我在父窗口中有这个功能:
<script language="javascript" type="text/javascript">
function window.reportChildActivity() {
SESSION_ALIVE = true;
window.setTimeout("pop_init()", SESSION_TIME);
}
</script>
在子窗口中:
<script type="text/javascript">
$(document).bind("mousedown keydown blur", function() {
window.parent.reportChildActivity(); });
</script>
无论我在子窗口中单击或使用多少键,当 SESSION_TIME 第一次用完时,都会调用我的 Jquery 超时代码。然后我的页面中有多个 Jquery 窗口告诉我单击以继续。就像事件正在被缓冲,当它们触发时,这些窗口都被多次生成。有人从中看出我做错了什么吗?谢谢!
---- 编辑 ----- 我正在添加我的 pop_init 函数和支持函数以供参考:
// remove all added objects and restart timer
function popup_remove() {
$("#popup_window").fadeOut("fast", function() { $('#popup_window,#popup_overlay').trigger("unload").unbind().remove(); });
//if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
$("body", "html").css({ height: "auto", width: "auto" });
$("html").css("overflow", "");
//}
window.setTimeout(pop_init, SESSION_TIME);
}
// session ajax call from button click
function session_refresh() {
SESSION_ALIVE = true;
$(".buttons").hide();
$("#popup_message").html("<center><br />Thank you! You may now resume using the application.<br /></center>");
window.setTimeout(popup_remove, 1000);
$("#popup_window").fadeOut("slow", function() { $('#popup_window,#popup_overlay').trigger("unload").unbind().remove(); });
window.setTimeout(pop_init, SESSION_TIME);
}
function popup_expired() {
if (!SESSION_ALIVE)
window.close();
}
// Main popup window handler
function pop_init() {
// show modal div
$("html").css("overflow", "hidden");
$("body").append("<div id='popup_overlay'></div><div id='popup_window'></div>");
//$("#popup_overlay").click(popup_remove); // removed to make sure user clicks button to continue session.
$("#popup_overlay").addClass("popup_overlayBG");
$("#popup_overlay").fadeIn("slow");
// build warning box
$("#popup_window").append("<h1>Warning</h1>");
$("#popup_window").append("<p id='popup_message'>Your session is about to expire. Please click the button below to continue working without losing your session.</p>");
$("#popup_window").append("<div class='buttons'><center><button id='continue' class='positive' type='submit'><img src='images/green-checkmark.png' alt=''/> Continue Working</button></center></div>");
// attach action to button
$("#continue").click(session_refresh);
// display warning window
popup_position(400, 300);
$("#popup_window").css({ display: "block" }); //for safari using css instead of show
$("#continue").focus();
$("#continue").blur();
// set pop-up timeout
SESSION_ALIVE = false;
window.setTimeout(popup_expired, 30000);
}
【问题讨论】:
标签: javascript asp.net jquery iframe parent-child