09 April 2009

0 JavaScript code to refresh the parent window on clicking of a button in a popup opened from the parent window

Here is the JavaScript code to refresh the parent window on clicking of a button in a popup opened from the parent window. The same popup could be created by different parent windows. On clicking of the button in the popup the corresponding parent window should be refreshed.

The refresh function should be in the corresponding parent windows JavaScript. Instead of var i = “/ShowInbox.do”; give the path of the corresponding parent window.  Return 0 if the parent window need not be refreshed.

// for parent page refresh after clicking ok in a popup

// this function should be in the corresponding parent windows script

 

function refresh(){

      var i="/ShowInbox.do";

      return i;

}


        Call the confirm function on clicking of the button in the popup. This in turn calls the corresponding parent windows refresh function. The refresh function returns the path of the parent window. If return is 0 the parent window is not refreshed and the popup window is closed. If a path is returned the parent window is refreshed with the corresponding path and popup window is closed.

//for reload of the opener of the confirmation

// this function should be in the pop-up’s JavaScript

 

function confirm() {

      var contextPath=document.getElementById("context").value;

      var i=window.opener.refresh();

      if (i==0){

            window.close();

      }

      else{

            window.opener.document.forms[0].action=contextPath+i;

            window.opener.document.forms[0].submit();

            window.close();

      }

}





0 comments:

Feeds Comments

Please give your valuable comments.