Link to home
Start Free TrialLog in
Avatar of prashanth9
prashanth9

asked on

Refresh Parent window after opening a child window and submitting

Hello gurus,

The situation is that I have a list page (parent page) with a list of items that the user wants to print. Once he selects all the items and clicks 'Print' on the list page, I open a child window, submit the request to the backend, change the modified timestamp for all the selected records in the database and get back the response and show it to the user. After that I want to refresh the parent window with the last modified date for all the selected items....

The problem is that the backend process might take any amount of time and I have to refresh the parent page only when I get all the data back....Can anyone suggest how I can achieve this ? I have tried putting a wait time after submitting but that doesnt seem to work...Here is the relevant code...Please help...

-----------------------------------
CHILD WINDOW
------------------------------------
  if (IE5)
    _wPrint = window.open('', PRINT_POPUP_NAME, 'scrollbars=yes,height='+PRINT_POPUP_HEIGHT+',width='+PRINT_POPUP_WIDTH+',left=100,top=100,resizable=yes,status=no,toolbar=no,directories=no,menubar=no', false);
  else
    _wPrint = window.open('', PRINT_POPUP_NAME, 'scrollbars=yes,height='+PRINT_POPUP_HEIGHT+',width='+PRINT_POPUP_WIDTH+',screenX=100,screenY=100,resizable=yes,status=no,toolbar=no,directories=no,menubar=no', false);
 
  _wPrint.document.write('<html><title>Items</title><P valign="middle" align="center" style="font-family: Arial"><B>Please wait while the page is formatted for printing...</B></P></html>');
  theForm.target = PRINT_POPUP_NAME;
  theForm.method = 'post';
  theForm.submit();


-----------------------------
PARENT WINDOW LOGIC
----------------------------
function printDetails() {
  var f = document.pilistform;
  var numberChecked = 0;
  if (f.detaildata) {
      var itemInfo = "";
            for (var i=0; i<detailData.length; i++) {
                  if(detailData[i].checked) {
                        itemInfo += detailData[i].value + ';';
                        numberChecked++;
                  }
            }
    if (itemInfo.length > 0) {
      f..value = itemInfo.substring(0, itemInfo.length - 1);
      callItemPDFPrint(f, "printitemrequest", "viewprintitemrequest");
      reload_list();
      return;
    }
    alert("Select One Item First");
      }
}

function reload_list() {
      //Logic to reload the parent
}


Avatar of devic
devic
Flag of Germany image

in popup in body onload call function from parent window
<body onload="opener.reload_list();">

or refresh parent window
<body onload="opener.reload();">
Avatar of NetGroove
NetGroove

The normal way of doing would be that the print output caries a function with it to refresh the parent window.

Are you able to extend the print output with a function for parent window refresh or is this forbidden for you?

If it is forbidden or for any other reason not possible to change the form submit response, then is the only option you have to poll the wait window in a timer interwal and observe wether some detail has changed, for example a global variable in that popup window.

Which method would you prefer: popup polling or response modify?

How about placing a target in you form and letting the server generate the new page

<form href="filetogenerateupdatedlist.php" target="nameofparetwindow">

that way the server regulates the update to happen only when the form data have been handeled.

You can give the parentpage (or any window) a name with javascript:
     window.name = ""nameofparetwindow";

regards JakobA
Avatar of prashanth9

ASKER

Netgroove,
I have tried putting in a wait method in my parent window and depending on the number of items that get selected, I used to wait for certain number of seconds before refreshing the parent page but this proved to be unreliable....My items sometimes take very less time and sometimes very long depending on the network and database connections...I didnt understand your questions fully but if you can see the code, I call the child window from my parent window and try to refresh the parent window with logic written in it. I only need logic to make sure that I wait for as long as the child window is done processing before the parent gets refreshed...

Jakoba and Devic,

I will try implementing each of the solutions you have suggested today and see which one works. I had one question however.

How do I make sure that the parent window refreshes only after the child window gets all the content stream from the backend ? The child window might take anywhere between 1 sec and 20 seconds to get the data...I want to refresh my parent window ONLY AFTER all the processing in the child window is done.

Can anyone shed some light on this and let me know how to make sure this happens ?

Thanks
prashanth9,

ONLY AFTER all the processing in the window is done, come EVENT ONLOAD
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
I cannot accept any of the above answers as none of them worked for me. I implemented this logic using a different technique where I catch a Javascript Exception. Refer to this link to see how I solved the same problem :

https://www.experts-exchange.com/questions/20791330/document-readyState-'complete'-giving-an-error.html

So, no points to anyone here.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial