+ Start a Discussion
boihueboihue 

Displaying of Visualforce Page in a new Window

Hi,
Do any expert know how to display a Visualforce Page in a new separated Window when clicking from a button of the current page?
Best regards!
aalbertaalbert
The easiest way to do this is when the VF page uses a standard controller or controller extension. If so, then just create a new custom button and set the Behavior to "Display new window" and redirect it to a Visualforce page.

If the VF page uses a custom controller, then you might have to create an scontrol that simply does the redirect to the VF page url. And then create a custom button to open a new window for the SControl.


boihueboihue
Thanks aalbert, but in my case, I want to create a new separated Window for a new Visualforce Page from the apex:commandButton of the current Visualforce Page.
Regards!
aalbertaalbert
I see that the <apex:commandLink> attributes support setting the "target" which can open up a new window. And also set the action attribute to the controller's method which redirect to a new Visualforce page:

Code:
VF Page snippet:
<apex:commandLink action="{!reDirect}" target="_blank" value="Save" id="theButton"/>


Apex Class snippet:

public PageReference reDirect() {
   
   PageReference pageRef = new PageReference('http://www.google.com');
   return pageRef;       
}

 

I don't see the target attribute available for the <apex:commandButton>.
chimerachimera

I had the same situation, using JavaScript is easier but in my experience you have to manage the page state yourself. Apex:CommandLink has the target="_blank" support. But it will appear as link. You can use little CSS to make commandLink appear as button while opening the URL in new window.

 

<style type="text/css">
a.linkAsBtn,
a.linkAsBtn:hover {
text-decoration: none;
padding: 3px 6px;
}
</style>

 

<apex:commandLink value="Do Something" action="{!doSomething}" target="_blank" styleClass="btn linkAsBtn"/>

 

Where doSomething is a action function in controller which returns page reference.