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
AK-2AK-2 

Redirect user from embedded VF page

I have a VF page that's embedded within the standard opportunity page layout. When user clicks on a commandbutton on the VF page, the user needs to be redirected to a custom page from the opportunity page. I have a commandbutton on the VF page with controller action that has code something like this:
 
Public PageReference OpenCustomPage(){
 
 PageReference pr = new PageReference('apex/MyCustomPage?LongVersion=1&Id='+optty.Id+'&retUrl=/'+optty.Id);
 
 pr.setRedirect(true);
 return pr;

}
However, when user clicks on the button instead of the entire opportunity page getting replaced, the VF page within the Opportunity page is replaced and the user remains on the opportunity page.

How can I redirect the user to the custom page completely? Please note the command button is on the VF page not on the opportunity page.

Thank you. 
 
Best Answer chosen by AK-2
AK-2AK-2
Okay, I was able to solve this by using javascript instead of controller action. I added onclick event handler on the vfpage like this:
 
<apex:commandButton value="OpenCustomPage" action="{!xxx}"  
            onclick="window.top.location.replace('/apex/MyCustomPage?id={!Optty.Id}&retUrl=/{!Optty.Id}&LongVersion=1');return false;"
            />