0

I open a visualforce page in an iframe witch contain two commandButton.

The buttons call functions on the class.

At the end of my functions, i made a redirection with PageReference but the redirection is made inside the iframe...

How can i do the redirection in the same window, a new window, or just refresh the page ??

Thanks for the help.

1

You can render a <apex:outputPanel on the action of a <apex:commandButton as below. And inside the <apex:outputPanel you can refresh the parent page with the redirect URL with this script window.top.location.href = '{!redirectUrl}';. Hope this helps.

VF Page

<apex:page standardController="Opportunity" extensions="Opp_Ext" >
    <apex:form >
        <apex:commandButton value="Do Stuff" action="{!doStuffAndRedirect}" rerender="redirectPanel" />
        <apex:outputPanel id="redirectPanel" >
            <apex:outputText rendered="{!shouldRedirect}">
                <script type="text/javascript">
                    window.top.location.href = '{!redirectUrl}';
                </script>
            </apex:outputText>
        </apex:outputPanel>
    </apex:form>
</apex:page>

Controller

public class Opp_Ext {
    private ApexPages.StandardController stdController;
    public String redirectUrl {public get; private set;}
    public Boolean shouldRedirect {public get; private set;}

    public Opp_Ext(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        shouldRedirect = false;
    }

    public PageReference doStuffAndRedirect() {
        shouldRedirect = true;
        redirectUrl = stdController.view().getUrl();
        return null;
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.