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
drewpiston.ax678drewpiston.ax678 

Can an apex method return a page reference to top window?

Hi,

 

I have a visualforce page that may need to run in an iFrame.  When a user hits a commandbutton, I need it to call an Apex method (to update some records) but then I'd like to be able to have the entire window (not just the iFrame) load the return URL.  Is this possible?

 

It doesn't look like there's any way to set a target on a pagereference, but what I want to do is something like:

 

 

public PageReference submitConfirmation() {

     PageReference pr = new PageReference('urlgoeshere.com');

     pr.setTarget('_top'); // this line is NOT real code - there is no such PageReference method

     return pr;

}

 

 

Any advice?

 

Thanks,

 Drew

mtbclimbermtbclimber

You'll need to write some client side code that redirects the parent document. I'd recommend hooking it in with the oncomplete attribute on commmandbutton.

Bhawani SharmaBhawani Sharma

Instead of redirecting it from the class, you can take the advantage of the Javascript:

 

<apex:commandButton action="{!doSomething}" onComplete="doRedirect()" />

 

<script>

function doRedirect()

{

window.parent.location.href = 'urlgoeshere.com';

}

<script>

tonybrasunastonybrasunas

Perfect, with one tweak. If you need to pop out of an iframe that the visual force page is in, use:

 

function doRedirect()

{
        top.location= 'urlgoeshere.com';
}

Serhiy FyrinSerhiy Fyrin
Use target="_top" on an apex:form that contains an apex:commandButton.