Friday, May 18, 2012

Javascript - Reload parent window from child window

Reload Using JavaScript:---

Oh.. How many time this type of requirement generate where we have to close child(Pop up) window and reload Parent Window as a result of this due to which we can see the resultant changes occurs in Parent Window. There are different JavaScript functions uses for this among them one or more working properly for the requirements. I uses different functions in past for this purpose and they are as given:--

1. <script>
        //alert({!isSaved});
        if({!isSaved} == true){
       // alert({!isSaved});
       // window.parent.location.reload();
        window.opener.location.reload();
        window.close();
    }
    </script>
 
2.  <script>
    function refresh(){
        opener.focus();
        opener.location.href = opener.location;
        self.close();
        }
    </script>

 3.  <script>
      function saveRec(){ 
            alert('Hi');
            UploadAttachment();
            var success = {!isSaved};
             // alert(success);
            if(success!= true){
                 window.open("https://ap1.salesforce.com/0039000000CNgaa");
                 window.close();
            }
        }
       </script>

4.    <script>
       function saveRec(){
           //alert('Hi');
           var parent = window.opener;
           parent.location ='https://ap1.salesforce.com/0019000000Ap7rK';
           UploadAttachment();
           //alert('reload done');
           window.location.reload(true);
           window.close();
       }
       </script>

 5. <script>
     function closepopup()
     {
          window.close();
          window.opener.location.href="give the parent url here";
      }  
      </script>

6. <form action="whatever" onsubmit="window.opener.location.reload();">

7. function CloseAndRefresh()
    {
        opener.location.reload(true);
        self.close();
    }
    </script>

 8. function SaveSetting()
     {
          //alert("Settings have been saved successfully.");
          var url = "CalInstitutions.aspx";
          opener.location.reload(true);
          //opener.history.go(0);
          opener.focus();
          self.close();
     }

9. function refreshParent() {
        window.opener.location.href = 'index.php';
         if (window.opener.progressWindow)
              window.opener.progressWindow.close();
              window.close();
    }

10.<script>
     function refreshmainwindow() {
     // this will close the pop up window
     window.close();
    // this will reload the parent window...
    if (!window.opener.closed) {
         window.opener.location.reload();
         window.opener.focus();
   }
   </script>


Enjoy Coding , Implement Thinking and Cloud is Future.
                                                                          ------  Abhinav Sharma

2 comments:

  1. Oh.. it's like a "Reload method altogether". Good work.

    ReplyDelete