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
nelloCnelloC 

Parent page refresh on popup

I have a commandbutton that opens a popup window but when the popup is launched the parent page seems to refresh. How can I prevent the parent page refresh from happening?

 

Any help much appreciated.

 

<script> var newWin=null; function openPopup() { var url="/apex/DocumentExt"; newWin=window.open(url, 'Popup','height=500,width=400,left=100,top=100,resizable=no,scrollbars=no,toolbar=no,status=no'); newWin.focus(); return false; } </script> <apex:commandButton onclick="openPopup();" value="Popup" immediate="true"/>

 


 

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Try putting "return false" part inside the onClick attribute.

 

<apex:commandButton onclick="openPopup();return false;" value="Popup" immediate="true"/> 

All Answers

GoodGrooveGoodGroove

You need to set an empty rerender attribute on the command button.

 

<apex:commandButton onclick="openPopup();" rerender="" value="Popup" immediate="true"/>

 

 

 

nelloCnelloC

Many thanks for your repsonse. I've just tried setting an empty rerender attribute but the bahaviour remained the same. So I also tried the following and that seemd to work okay.

 

 

<apex:commandButton onclick="openPopup();" reRender="dummy" value="Attach file" immediate="true"/> <apex:outputText rendered="true" id="dummy" rendered="false"></apex:outputText>

Any idea why the empty rerender attribute didn't work? Is it a browser issue (I'm using Firefox 3.5)? I'd rather not have the dummy outputtext if at all poss.

 

nelloCnelloC
Okay just found that I don't need the outputtext, just specifying an id that doesn't exist in the rerender attribute (i.e. "dummy") seems to work fine. Thanks for your help.
prageethprageeth

Try putting "return false" part inside the onClick attribute.

 

<apex:commandButton onclick="openPopup();return false;" value="Popup" immediate="true"/> 

This was selected as the best answer
nelloCnelloC
Prageeth, works perfectly and seems faster too. Many thanks.