Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Javascript time to force full postback

Posted on 2012-08-13
Medium Priority
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
  • 2

Expert Comment

ID: 38287309
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


Expert Comment

ID: 38287405
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.

Accepted Solution

Andy Green earned 0 total points
ID: 38337667
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


Author Closing Comment

by:Andy Green
ID: 38356869
I have found my own solution.

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
Suggested Courses

572 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