function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PremanathPremanath 

How to write code for save & close operation done in one button click

Hi ,

I have one javascript button , Go with the any record and when we click on button one popup window came 

i.e VF page window.. 

Add one field and click on save button on that widow it should be save and close...

 

Javascript button code is this,

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

 

var url="/apex/commentspage?&id= {!Contact.Id}";

newWin=window.open(url, 'Popup','height=500,width=600,left=150,top=150,resizable=yes,scrollbars=no,toolbar=no,status=no');

if (newWin.focus())
{
newWin.focus();

}

 

 

After creation of button.

Go with contact record, there is one button available right,

Then click on that button one VF page popup window came.

The VF page is.. 

<apex:page controller="commentspage" showHeader="false" sidebar="false" showChat="false" standardStylesheets="false" >

<script type="text/javascript">
function closeWin(){
self.close();
}
</script>

<apex:form > <br/><br/>
<div align="center">
<apex:inputTextarea value="{!CommentText}"/><br/><br/>
<apex:commandButton oncomplete="closeWin" action="{!save}" value="Save" id="theButton"/>
</div>
</apex:form>
</apex:page>

 

 

The Action performed on controller...

Please solve my problm...

Best Answer chosen by Admin (Salesforce Developers) 
PremanathPremanath

Like this way we can do it simply..

 

<apex:commandButton action="{!save}" value="Save" rerender="AJAXTest" status="AJAXStatus"/>
<apex:actionStatus startText="(Saving...)" stopText="" onStop="window.top.close();" ID="AJAXStatus"/>

 

 

 

prem

All Answers

DJ Rock your own styleDJ Rock your own style

Hi,

 

Instead of save.close() try window.close().

 

Sometimes window.close can be a  problem in IE. To avoid that u can use the following.

 

function windowclose() {
        if (navigator.appName  == "Microsoft Internet Explorer") {
            window.open('', '_self', '');
            window.close();
        }  
        else  {
           window.close();
        }

    }

 

Thanks,

 

Dave

PremanathPremanath

Hi Thanks for reply

It's not working ...

Actually my question is: : :   The pop up window is vf page only 

                                                 There is one text area  and one save button available.

 If we click on save button it should be save and close that popup.

 

<apex:page controller="commentspage" showHeader="false" sidebar="false" showChat="false" standardStylesheets="false" >

<script type="text/javascript">
function windowclose() {
if (navigator.appName == "Microsoft Internet Explorer") {
window.open('', '_self', '');
window.close();
}
else {
window.close();
}

}
</script>

<apex:form > <br/><br/>
<div align="center">
<apex:inputTextarea value="{!CommentText}"/><br/><br/>
<apex:commandButton onclick="windowclose()" action="{!save}" value="Save"/>
</div>
</apex:form>
</apex:page>

 

 

 

The popup button created with this below code  setup-->contact-->buttons and links --> javascript button

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

var url="/apex/commentspage?&id= {!Contact.Id}";

newWin=window.open(url, 'Popup','height=500,width=600,left=150,top=150,resizable=yes,scrollbars=no,toolbar=no,status=no');

 


Dipa87Dipa87

Do You want the whole VF page to be a pop up  or a particualr section???

If you need a particular section we can use a modal pop up.

Its easy to open and close a modal pop up.

Something like this you can try

                   <apex:outputpanel id="tstpopup" rendered={!showPopUp}> 

                      //contents inside the pop up.

                            <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!showPopUp}"/>
                                <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!showPopUp}">

                                    //showPopUp is boolean getter setter variable.make it true or false on click of button.
                                        <apex:pageBlock >
                                                <apex:pageBlockButtons >
                                                    <apex:commandButton value="Save" action="{!saveFields}" reRender="tstpopup"/>
                                                    <apex:commandButton value="Cancel" action="{!closePopUp}"/>
                                               </apex:pageBlockButtons>                    
                                       </apex:pageBlock>
                               </apex:outputPanel>
                        </apex:outputPanel>
  

Add the following style for the modal pop up

<style type="text/css">

.popupBackground{
            background-color:black;
            opacity: 0.20;
            filter: alpha(opacity = 20);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;
    }  

   .custPopup{
                background-color: white;
                border-width: 0px;
                border-style: solid;
                left: 40%;
                top:30%;
                align:center;
                padding:10px;
                position: absolute;
                width: 350px;
                 z-index: 9999;  
           
                
                              
    }

</style>

PremanathPremanath

Thanks for your reply actually i got the answer priviously...

 

Thank you guys...

PremanathPremanath

Like this way we can do it simply..

 

<apex:commandButton action="{!save}" value="Save" rerender="AJAXTest" status="AJAXStatus"/>
<apex:actionStatus startText="(Saving...)" stopText="" onStop="window.top.close();" ID="AJAXStatus"/>

 

 

 

prem

This was selected as the best answer