You need to sign in to do that
Don't have an account?
drewpiston.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
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.
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>
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';
}