You need to sign in to do that
Don't have an account?
dsh210@lehigh.edu
CommandButton target attribute
Hey all,
So I am using some command buttons to execute some page redirects via page references, but I was wondering how I could specify the target for the new window. I know that outputLink has the target attribute, but I would like to stick with the default Salesforce style on the buttons and not have to recreate it myself. Right now I have resorted to using javascript because I can specify "_parent", but does anyone know how to accomplish this with a PageReference?
Thanks!
All Answers
Example here is yours commandbutton code in
<apex:commandButton action="{!ab}" value="send" id="theButton"/>
In yours controller code write a method like this
public PageRefreance ab()
{
String url = null;
url = '\apex\yoursvfpage';
PageRefreance p = null;
p = new PageRefreance(' url');
p.sendRedirect(true);
return p;
}
This is a sample you can improve it.
Okay so I have that working to open in the current window, but suppose I want a popup now, is there any way to change the target from "_parent" functionality to something along the lines of what "_blank" provides?
Hello,
You can used javasript call directly in <apex:commandButton
Example:
<apex:commandButton onclick="window.open('{!DestURL}');" value="Generate" />
Thank you Solo!
Works like a charm!
Hi Solo,
How do I find out the 'DestURL'? Please help me, Thanks!
Hello!
DestURL is actually URL you want to be redirected after hitting the button
Regards!
Thank you Solo!
To open the URL in the same page your are on, you can use the action="{!DestURL}" attribute or just modify @Solo's syntax from window.open(..) to be location.href=".."
Example (open in same window):
Example (open in new window):
Also, for best practice for creating URLs to visualforce pages, please see the URLFOR function documentation:
http://www.salesforce.com/docs/developer/pages/Content/pages_variables_functions.htm
http://www.salesforce.com/docs/developer/pages/Content/pages_compref_commandButton.htm
<apex:commandLink action="{!reDirect}" target="_blank" value="Save" id="theButton"/>
U can use targate _blank
Regards ,
Harish.R