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
Renato Garofalo 13Renato Garofalo 13 

Go to a specific URL after one click inside a VF page

I'm using a script and windows.open function to go to a specific URL when a user click a button on the VFpage. Something is going wrong because after the click the same page is reloaded.
SCRIPT:
<script type="text/javascript"> function goback() { window.open(retURL); } </script>


Inside the retURL variable, there is the URL where I want to go, something like:https://eu6.salesforce.com/0015800000DuQWsAAN'
button:
<apex:commandButton action="{!deleteContract}" value="Elimina Contratto e prodotti selezionati" immediate="true" onclick= "goback()" /> </apex:pageBlockButtons>


How can I solve this problem?
Swaraj Behera 7Swaraj Behera 7
Hi Renato,Can you please use the below code and let me know.
 
<script type="text/javascript">
 function goback() 
 { 
 	window.open("https://eu6.salesforce.com/0015800000DuQWsAAN");

  } 
 </script>

<apex:commandButton  value="Elimina Contratto e prodotti selezionati" action="{!deleteContract}" onclick= "goback();" immediate="true" action="{!deleteContract}" /> </apex:pageBlockButtons>

 
Rohit K SethiRohit K Sethi
Hi ,

When you execute the script after that the action is executed and when action is completed it reload the whole page because you not set the specific section for reRender.

So you can done through two ways:

1. Set return false in onclick and this will execute  only your script but your action can not executed: 
<apex:commandButton value="Elimina Contratto e prodotti selezionati" action="{!deleteContract}" onclick= "goback();return false;" immediate="true" action="{!deleteContract}" /> </apex:pageBlockButtons>
2. Set the reRender the particular section or set oncomplete as "return false".


Thanks.