Note that there are some explanatory texts on larger screens.

plurals
  1. POReporting child window's events to parent window to reset timer value of user timeout code
    text
    copied!<p>I've got a Jquery function that I wrote which blacks out the screen after a certain amount of inactivity, creates a pop-up that allows the user to click a button to stay logged in, and logs them out (closing the application window) if they do not respond in time.</p> <p>The environment is ASP.NET (VB). We don't technically use master pages, but we do have a parent page in which our header, footer and nav reside, and my Jquery code is called from that window, loaded via an IFrame.</p> <p>My problem is that if one is working in a child window, the parent window doesn't recognize that the system is in use, and will automatically engage at the allocated time.</p> <p>I've tried everything under the sun I can think of and nothing works properly. My event handler is working, and it does call the parent window function, but the timer is not being reset.</p> <p>I have this function in the parent window: </p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; function window.reportChildActivity() { SESSION_ALIVE = true; window.setTimeout("pop_init()", SESSION_TIME); } &lt;/script&gt; </code></pre> <p>And this in the child window: </p> <pre><code>&lt;script type="text/javascript"&gt; $(document).bind("mousedown keydown blur", function() { window.parent.reportChildActivity(); }); &lt;/script&gt; </code></pre> <p>No matter how much I click or use keys in the child window, my Jquery timeout code is called when SESSION_TIME runs out the first time. And then I get multiple Jquery windows in my page telling me to click to continue. It's like the events are being buffered and when they fire these windows are all being spawned multiple times. Does anyone see from this what I'm doing wrong? Thanks!</p> <p>---- EDIT ----- I'm adding my pop_init function and supporting functions for reference:</p> <pre><code>// 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("&lt;center&gt;&lt;br /&gt;Thank you! You may now resume using the application.&lt;br /&gt;&lt;/center&gt;"); 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("&lt;div id='popup_overlay'&gt;&lt;/div&gt;&lt;div id='popup_window'&gt;&lt;/div&gt;"); //$("#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("&lt;h1&gt;Warning&lt;/h1&gt;"); $("#popup_window").append("&lt;p id='popup_message'&gt;Your session is about to expire. Please click the button below to continue working without losing your session.&lt;/p&gt;"); $("#popup_window").append("&lt;div class='buttons'&gt;&lt;center&gt;&lt;button id='continue' class='positive' type='submit'&gt;&lt;img src='images/green-checkmark.png' alt=''/&gt; Continue Working&lt;/button&gt;&lt;/center&gt;&lt;/div&gt;"); // 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); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload