Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery error on window.load()
    primarykey
    data
    text
    <p>I'm new to Jquery, but I'm using it in a .NET 2.0 project to time our users out of the system after 13 minutes of inactivity. I've got a function that basically blacks out the screen and gives them a button ton continue working. It's been working for awhile, but only works inside of "child" windows because of the way I implemented it.</p> <p>We're not using Master Pages technically, but I am trying to embed the code in what is our equivalent of a master page, and I'm running into a javascript error. The code in question is:</p> <pre><code>$(window).load() { window.setTimeout("pop_init()", SESSION_TIME); } </code></pre> <p>The error I'm getting is that a ";" is expected. I've tried:</p> <pre><code>$(window).load() { window.setTimeout("pop_init()", SESSION_TIME); }; </code></pre> <p>and also tried:</p> <pre><code>$(window).load(function() { window.setTimeout("pop_init()", SESSION_TIME); }); </code></pre> <p>all with the same result. Thanks in advance for your time and any possible suggestions!</p> <p>Here is the code for my pop_init function:</p> <pre><code>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()", 1000); } </code></pre> <p>Well, I've made sure that all dependent functions are located above the code that calls them now, and I'm still getting the same error, so I'm at a loss. The odd thing is that my overlay fades in, and then the error is thrown - but my popup with the continue button never shows. So it's almost as if the error is between the overlay and the #popup_window construction. I'm attaching my complete .js file. There are some other functions in it that aren't concerned with this, but are for another part of the system, but I'm including them for completeness and the chance that perhaps there is interference of some sort:</p> <p>// Following code is to handle session timeout // Global variable used to set repeated session timeout calls. // Set SESSION_TIME to (# seconds) * 1000 for the total milliseconds // to wait before sending the popup windows to the user. // You should give the user two minutes before the session times out to respond, // e.g. for a 15 minute timeout, set it to 13 * 60 * 1000 = 780000 (~ 13 minutes). var SESSION_TIME = 60000;</p> <p>// Global variable used to test if the session has expired. Set to true until popup // is shown to the user. Reset when they click Continue. var SESSION_ALIVE = true;</p> <p>// determine size of popup window and adjust position function popup_position(P_WIDTH, P_HEIGHT) { $("#popup_window").css({ marginLeft: '-' + parseInt((P_WIDTH / 2), 10) + 'px', width: P_WIDTH + 'px' }); }</p> <p>// 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); }</p> <p>// session ajax call from button click function session_refresh() { SESSION_ALIVE = true; $(".buttons").hide(); $("#popup_message").html("<br />Thank you! You may now resume using the system.<br />"); window.setTimeout("popup_remove()", 300); $("#popup_window").fadeOut("slow", function() { $('#popup_window,#popup_overlay').trigger("unload").unbind().remove(); }); window.setTimeout("pop_init()", SESSION_TIME); }</p> <p>// Main popup window handler function pop_init() { // show modal div $("html").css("overflow", "hidden"); $("body").append(""); //$("#popup_overlay").click(popup_remove); // removed to make sure user clicks button to continue session. $("#popup_overlay").addClass("popup_overlayBG"); $("#popup_overlay").fadeIn("slow");</p> <pre><code>// 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()", 1000); </code></pre> <p>}</p> <p>// First call to popup window $(window).load(function() { window.setTimeout("pop_init()", SESSION_TIME); });</p> <p>function popup_expired() { if (!SESSION_ALIVE) //window.location.href = "login.asp"; //window.location.href = "default.aspx"; window.close; }</p> <p>function replaceBadCharacters() { // Get all textboxes and text area controls $('input[type=text], textarea').each(function() { var txtobj = $('#' + this.id); txtobj.attr("value", txtobj.attr("value").replace(new RegExp(String.fromCharCode(8216), "g"), String.fromCharCode(39))); // Microsoft Word left-side apostrophe txtobj.attr("value", txtobj.attr("value").replace(new RegExp(String.fromCharCode(8217), "g"), String.fromCharCode(39))); // Microsoft Word right-side apostrophe txtobj.attr("value", txtobj.attr("value").replace(new RegExp(String.fromCharCode(8220), "g"), "'")); // Microsoft Word left-side quotes txtobj.attr("value", txtobj.attr("value").replace(new RegExp(String.fromCharCode(8221), "g"), "'")); // Microsoft Word right-side quotes }); } // End of timeout code //-------------------------------------------</p> <p>// Following code is to warn users on Case Entry/Edit page that case will be saved if they click certain links // (like to add Notes, change Collection Tables, etc.) var calling_obj;</p> <pre><code>// call from cancel button click function save_abort() { popup_remove(); } // call from continue button click function save_continue() { //alert(calling_obj.id); __doPostBack(calling_obj.id, ''); popup_remove(); } function warn_save(obj) { // show modal div //alert(obj.id); $("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").addClass("popup_overlayBG"); $("#popup_overlay").fadeIn("slow"); // build warning box $("#popup_window").append("&lt;h1&gt;Save Case?&lt;/h1&gt;"); $("#popup_window").append("&lt;p id='popup_message'&gt;&lt;center&gt;Navigating away from the current page will automatically save this Case. Do you want to continue?&lt;/center&gt;&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;Yes&lt;/button&gt;&amp;nbsp;&lt;button id='cancel' class='positive' type='submit' alt=''&gt;&lt;img src='images/delete.png' alt=''/&gt;No&lt;/button&gt;&lt;/center&gt;&lt;/div&gt;"); // attach action to button $("#continue").click(save_continue); calling_obj = obj; $("#cancel").click(save_abort); // display warning window popup_position(400,300); $("#popup_window").css({display: "block"}); //for safari using css instead of show $("#continue").focus(); $("#continue").blur(); } // Case Entry div expand/close functions function close_div_acct() { $("#div_acct").hide(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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