You need to sign in to do that
Don't have an account?

opening a new window from apex-code
Hello,
I have a visualforce page with a command Button. When this is pressed some work is done in the page-reference of the controller-extension. During this work it is sometimes necessary to open new Windows in which are PDF-Documents are generated and diplayed. Is it possible to open a second, third, forth ... window with a visualforce page rendered as PDF directly from the apex code without leaving the original window. In the pagereference I think, I can only pass one new page, which is then displayed in the actual window, but I want to stay on this window with the original content and open the others for the user, who can then print them?
Thanks
Harry
You need not necessarily change the visualforce page CommandButton to HTML button and then add onclick event to that button. Even the visualforce page CommandButton supports onClick event:
<apex:commandButton value="Submit" action="{!controlleraction}" onClick="window.open('/apex/VFPage');"/>
All Answers
As you probably know, you can't open a window from Apex code. But you can change your VF page's commandButton to a regular HTML input type="button", and add an onClick event handler that uses JavaScript to open a new window, setting the new window's URL to the VF page you want the user to see. Does that let you do what you want to do?
Hello Mr. Kahn,
thanks for your quick reply. I did not know that it is impossible to open a new Window from apex. So I have 2 more questions to solve my problem:
1) How can I change an apex command button to a html button?
2) Can I then open more than one Window and let the user remain in the old one?
Thanks
Harry
You're not making the Apex code launch the new window. It's Visualforce that provides the user interface. Apex provides the behind-the-scenes logic that runs on the Salesforce servers.
You probably have some VF code like this:
And you probably have a controller, written in Apex, that includes a method named SomeAction() that returns a PageReference to the page you want the user to see in the new window. Let's assume that the page is /apex/MyNewVFPage.
Change your VF code to something like this:
When the user clicks this button, the onClick event's JavaScript code will open a new window, and nagivate to the given URL.
There are other parameters you can use when you call window.open() -- check the JavaScript documentation for details.
PS. Just for the record, it's "Ms" Kahn, not Mr. :)
You need not necessarily change the visualforce page CommandButton to HTML button and then add onclick event to that button. Even the visualforce page CommandButton supports onClick event:
<apex:commandButton value="Submit" action="{!controlleraction}" onClick="window.open('/apex/VFPage');"/>
You can use target="_blank" to redirect to new page on clicking link
<apex:commandLink style="color:blue" value="Link to Attachment" action="{!controllerMethod}" target="_blank"/>