+ Start a Discussion
ssssssss 

how to close the child window

Hi All,

 

In my application i am able to open the new window using java script but i am unable to close the window.plz tell me how to close the child window.

My code is as follows:

 

VF1:

 

<apex:page standardController="CAF_Charge__c" extensions="g_popupwindow">
<h1> CAF Charge Detail </h1>
<apex:form >
<table>
 <tr>
  <td>
    <apex:outputText value="Charges Head"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <apex:inputText value="{!parentTextId}"/>
    <apex:commandLink value="search" onclick="popup('/apex/ge2')"/><br/>
  </td>
 </tr>
 <tr>
  <td>
    <apex:outputText value="Description Of Charges"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <apex:inputtext value="{!doc}"/>
  </td>
 </tr>
 <tr>
  <td>
    <apex:outputText value="Percentage"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <apex:inputtext value="{!percentage}"/>  
  </td>
 </tr>
<tr>
   <td>
    <apex:commandButton action="{!save}" value="Save"  />
    <apex:commandButton value="New"  />
   </td>
</tr> 
</table>

<script>
function popup(url)
{
    newwindow=window.open(url,'kkkk','width=400,height=400,top=0,toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,re sizable=yes,left=60,screenX=60,top=100,screenY=100');
    if (window.focus)
    {
     kkkk.focus()
    }
    newwindow.close();
}
</script>

</apex:form>
</apex:page>

 

VF2:

 

<apex:page standardController="CAF_Charge__c" extensions="g_popupwindow">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
      <apex:pageblocksectionItem >
          <apex:outputlabel value="Charges Head" for="SelectedFromPickList" />     
          <apex:selectList value="{!selectedRecordId}" size="0" id="SelectedFromPickList">
          <apex:actionSupport event="onchange" reRender="Course" action="{!something}"/>        
          <apex:selectOptions value="{!ChargeNames}"/>
          </apex:selectList>
      </apex:pageblocksectionItem> 
      <apex:commandLink value="ok" onclick="popup_close()"/>
   <!--   <apex:pageBlockSectionItem >
     
          <apex:selectRadio value="{!selectedRecordId1}" id="Course" layout="pageDirection" >
               <apex:selectOptions value="{!Charge_Field}"/>
                <apex:actionSupport event="onchange" action="{!nothing}" status="status" reRender="btnsave,btncncel"/>
             </apex:selectRadio>
       
      </apex:pageblocksectionItem>-->  
                                      
                              
  </apex:pageblocksection>
 </apex:pageblock>
 
 <script language="javascript" type="text/javascript">
   function popup_close()
   {
    
   newwindow= window.close();
    
   }
    
     </script>  
</apex:form>
</apex:page>

 

controller:

public class g_popupwindow
{

    public g_popupwindow(ApexPages.StandardController controller) {
    }
      public string parentText;
      public string selectedRecord;
      public string selectedCharge;
     
      Public string chargeshead{get;set;}
      Public string doc{get;set;}
      Public string percentage{get;set;}
      public string chead;
      List<SelectOption> values = new List<SelectOption>();
      public string getparentTextId()
            {
       return parentText;
      }
      public void setparentTextId(string values)
      {     
        this.parentText=values;
      }
   //
    public string getselectedRecordId()
    {
        return selectedRecord;
    }
    public void setselectedRecordId(string s)
    {     
        this.selectedRecord=s;
    }
    public string getselectedRecordId1()
    {
        return selectedCharge;
    }
    public void setselectedRecordId1(string s)
    {     
        this.selectedCharge=s;
    }
  
   
    public void something()
    {
    setselectedRecordId1(selectedRecord);
    }
    public void nothing()
    {
    }
    //....! Dispalying charge values as picklist
    public List<SelectOption> getChargeNames()
    {
      List<SelectOption> options = new List<SelectOption>();
      List<chiranjeevi__CAF_Charge__c> chargelist= new List<chiranjeevi__CAF_Charge__c>();
      chargelist = [Select chiranjeevi__Charges_Head__c FROM chiranjeevi__CAF_Charge__c ];
      options.add(new SelectOption('--None--','--None--'));
    
      for (Integer j=0;j<chargelist.size();j++)
      {
       options.add(new SelectOption(chargelist[j].chiranjeevi__Charges_Head__c,chargelist[j].chiranjeevi__Charges_Head__c));
      }
      return options;
    }
   
    //....! storing selected charge from picklist to radio buton here
   
    public list<selectoption> getCharge_Field() 
    {
      List<SelectOption> SelectedFromPickList = new List<SelectOption>(); 
      if(selectedRecord == NULL)      
      {
        SelectedFromPickList.add(new selectoption('','NONE'));
      }
       
      else
      {
         SelectedFromPickList.add(new selectoption('',' '+selectedRecord));
      }
         return SelectedFromPickList;
    }  
}

 

plz tell me how to do it.

Thanks in advance,

Manu..

SteveBowerSteveBower

If I understand your question correctly, you were able to open a new window using "window.open", but you don't know how to close it?   Did you look at: "window.close"?

ssssssss

Thank you so much for ur response,

 

I am able to open a child window and close it.Actually i am trying to do the lookups as in salesforce using visual force. i was dispalyed the values as picklist in child window.but i was unable to pass the child window picklist value into parent window text filed.plz guide me.

 

My code is as follows:

 

VF 1:

 

<apex:page standardController="CAF_Charge__c" extensions="g_popupwindow">
<h1> CAF Charge Detail </h1>
<apex:form >
<table>
 <tr>
  <td>
    <apex:outputText value="Charges Head"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <apex:inputText value="{!parentTextId}"/>
    <input type="button" onclick="openPopup()" value="search" />

  </td>
 </tr>
 <tr>
  <td>
    <apex:outputText value="Description Of Charges"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <apex:inputtext value="{!doc}"/>
  </td>
 </tr>
 <tr>
  <td>
    <apex:outputText value="Percentage"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <apex:inputtext value="{!percentage}"/>  
  </td>
 </tr>
<tr>
   <td>
    <apex:commandButton action="{!save}" value="Save"  />
    <apex:commandButton value="New"  />
   </td>
</tr> 
</table>

<script>
var newWin=null;
 function openPopup()
 {
    var url="/apex/ge2";
    newWin=window.open(url, 'Popup','height=500,width=400,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
    newWin.focus();
    
    return false;
 }
 function closePopup()
  {
    if (null!=newWin)
    {
      newWin.close();
    } 
  }
</script>

</apex:form>
</apex:page>

 

VF 2:

 

<apex:page standardController="CAF_Charge__c" extensions="g_popupwindow">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
      <apex:pageblocksectionItem >
          <apex:outputlabel value="Charges Head" for="SelectedFromPickList" />     
          <apex:selectList value="{!selectedRecordId}" size="0" id="SelectedFromPickList">
          <apex:actionSupport event="onchange" reRender="Course" action="{!something}"/>        
          <apex:selectOptions value="{!ChargeNames}"/>
          </apex:selectList>
      </apex:pageblocksectionItem> 
      <input type="button" onclick="CloseWindow()" value="OK" />
   <!--   <apex:pageBlockSectionItem >
     
          <apex:selectRadio value="{!selectedRecordId1}" id="Course" layout="pageDirection" >
               <apex:selectOptions value="{!Charge_Field}"/>
                <apex:actionSupport event="onchange" action="{!nothing}" status="status" reRender="btnsave,btncncel"/>
             </apex:selectRadio>
       
      </apex:pageblocksectionItem>-->  
                                      
                              
  </apex:pageblocksection>
 </apex:pageblock>
 
 <script language="javascript" type="text/javascript">
   function CloseWindow()
    {
      var winMain=window.opener;
      if (null==winMain)
      {
         winMain=window.parent.opener;
      }
      winMain.closePopup();
   }
    
  </script>  
</apex:form>
</apex:page>

 

Controller:

 

 

public class g_popupwindow
{

    public g_popupwindow(ApexPages.StandardController controller) {
    }
      public string parentText;
      public string selectedRecord;
      public string selectedCharge;
      public string SelectedFromPickList;
      Public string chargeshead{get;set;}
      Public string doc{get;set;}
      Public string percentage{get;set;}
      public string chead;      
        
    public string getselectedRecordId()
    {
        return selectedRecord;
    }
    public void setselectedRecordId(string s)
    {     
        this.selectedRecord=s;
    }
    public string getselectedRecordId1()
    {
        return selectedCharge;
    }
    public void setselectedRecordId1(string s)
    {     
        this.selectedCharge=s;
    }
  
   
    public void something()
    {
    setselectedRecordId1(selectedRecord);
    }
    public void nothing()
    {
    }
    //....! Dispalying charge values as picklist
    public List<SelectOption> getChargeNames()
    {
      List<SelectOption> options = new List<SelectOption>();
      List<chiranjeevi__CAF_Charge__c> chargelist= new List<chiranjeevi__CAF_Charge__c>();
      chargelist = [Select chiranjeevi__Charges_Head__c FROM chiranjeevi__CAF_Charge__c ];
      options.add(new SelectOption('--None--','--None--'));
    
      for (Integer j=0;j<chargelist.size();j++)
      {
       options.add(new SelectOption(chargelist[j].chiranjeevi__Charges_Head__c,chargelist   [j].chiranjeevi__Charges_Head__c));
      }
      return options;
    }
   
    //....! storing selected charge from picklist to radio buton here
   
     public list<selectoption> getCharge_Field() 
   
    {
   List<SelectOption> SelectedFromPickList = new List<SelectOption>();
    
      if(selectedRecord == NULL)      
      {
        SelectedFromPickList.add(new selectoption('','NONE'));
      }  
       
      else
      {
         SelectedFromPickList.add(new selectoption('',' '+selectedRecord));
        }
         return SelectedFromPickList;
    }  
}

 

Thanks in advance,

Manu..

SteveBowerSteveBower

My guidance is that what you're trying to do just doesn't seem to make a whole lot of sense.

 

My guidance is to stop coding immediately and start again, now that you have a better understanding of how visual force and apex work.  You've asked like 20 questions about this one bit of code, and you've ended up with something very wierd.

 

My guidance is, before you try writing *any* code again, write out in english what you're trying to accomplish and why.   At the very least you can use these as comments into your code which will help you explain it and understand it when you come back to it later.

 

My guidance is that Salesforce has a "style".  A set of visual interface behaviors.  A way of interfacing with it.  If you attempt to come up with a style of your own, popping up windows where they don't normally pop up, using your own html layout instead of just using Apex components,etc. you may eventually succeed in coming up with the interface you want, however it will far more painful than if you buy into the Salesforce look and feel that Apex components generate for you and just accept it.

 

Lastly, you seem to have spent an astounding amount of time working on this, asking a lot of questions to the board, etc.  You might consider that learning how to code through trial and error might not be the best strategy.  I'd advise you to find a mentor or tutor near you who you can sit down with for a few hours and they can go over the specifications with you, perhaps suggest different approaches, and when it's time to code, show you some standard ways of accomplishing the things you're looking to do.

 

Best of luck, Steve.