Javascript time to force full postback

Posted on 2012-08-13
Last Modified: 2012-09-01
I have a heavy AJAX site that has to run on IE6&7 - this is causing memory leaks.

The solutions after many weeks of debugging seems to be to have a full postback every now and then.

I currently have a javascipt timer that rund for 60 mins then does a document.forms[0].submit()

The problem with this is the page has pop up, and I dont want the page to postback while the user has a pop up open, as this clears.

I'm at the limit now of my JS skills. I need a javascript time function that I can stop when the pop up opens and continues when the pop up closes.

Doe anyone have such a script?

Question by:Andy Green
    LVL 6

    Expert Comment

    You could take the start time when you set your timeout for doing the postback, then just before opening the popup calculate the amount of time remaining and cancel the timeout. After the popup is closed you can then create a new timeout using the remaining time.

    I've not tested the following, but this is the approach I would take...

    // Initialisation
    // Start the count down to posting back and record the current time in milliseconds
    postbackId = setTimeout("postback()", 60000);
    startTime = (new Date()).getTime();
    // Before opening popup...
    // Get time remaining time.
    remainingTime = 60000 - ((new Date()).getTime() - startTime);
    // Now open popup...
    // After closing the popup..
    // recalculate the start time to be now - the time elapsed before the popup was opened, and timeout on the remaining time.
    startTime = (new Date()).getTime() - (60000 - remainingTime);
    postbackId = setTimeout("postback()", remainingTime);

    Open in new window

    LVL 1

    Expert Comment

    Heavy AJAX on IE6/7 requires extremely careful programming. The reload you are suggesting will probably only delay the memory issue, not prevent it.

    I have been there before, with an enterprise app that leaked memory up to where it wasn't usable anymore (after about 5-6 hours of usage). A reload helped, but not all memory would free up. After about 10 hours of usage, a reload didn't help at all - the IE process had to be killed.

    My advice is to look at the memory leaks and fix them. A common issue in IE6/7 is manipulation of DOM content that isn't there. Another big no no is to append/remove DOM elements instead of show/hide.
    LVL 3

    Accepted Solution

    Thanks for the replies, but I have found my own solution.

    I have the following Script:
    var secs
    var timerID = null
    var timerRunning = false
    var delay = 1000
    function InitializeClearDataTimer() {
        secs = 360 //set the timer delay
    function StopTheClock() {
        if (timerRunning)
        timerRunning = false
    function StartTheTimer() {
        if (secs == 0) {
        else {
            secs = secs - 1
            timerRunning = true
            timerID = self.setTimeout("StartTheTimer()", delay)

    Open in new window

    In the function that opens the pop up I have - StopTheClock()
    And in the function that fires the AJAX to re populate the grid I have -  StartTheTimer();

    This seems to work OK

    LVL 3

    Author Closing Comment

    by:Andy Green
    I have found my own solution.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now