You need to sign in to do that
Don't have an account?
How to close the current open window?
Hi Friends,
In my VF Page, we used two buttons "Save" and "Close". In Page, we are dispalying the current contacts for an Account.
When Clicking "Save"; the details are going to be stored/updated.
when clicking "Close"; the current window which is showing the details, has to be closed.
How to do that. I used javascript for this button on Event = onclick="closeWindow();"
I wrote the script as follows:
<script>
function closeWindow(){
window.close();
}
</script>
But, it is not working. Please suggest me, if any solutions are there.
Thanks in advance.
Regards,
Phanikumar
I don't think that is a good idea to close the window when user hits the button, because you can miss error messages. Mmmm.. If I were you, I'll use a extension controller to perform the save and set a Boolean flag to indicate close's action. After save, when your VF is refreshed, you'll do:
The controller:
And make sure that you have <apex:pageMessages/> at the beginning of the page.
Regards.
Hi Friend,
Thank you for your reply. I used the code which you replied to my query. But, in Save, i used the flag variable and i updated the code as said by you. After clicking save; validations are done, but, the window is not going to close.
Please see the code below:
Controller:
public pageReference save(){
Integer count = 0;
if(literatureOrderItemsList.size()>0){
update literatureOrderItemsList;
closeWindow=true;
message = 'Items Updated Successfully';
displayMessage = true;
}
In the page also, i wrote the script before </apex:form> tag as you provided.
But, it is not working. After clicking save, it is showing the same page with validation messages. Please suggest me how to do this.
Regards,
Phanikumar
Could you paste your visualforce's code, please?
(Please uses "Insert Code" button in your reply)
Thx!
Hi Friend,
Please see the VF Page code .
Regards,
Phanikumar
But... There is not "standardController", "controller" or "extensions" in <apex:page> tag.. How are you linking the page to the controller?
By the way.. You can use <apex:pageMessages> for render messages to the user, in the controller you code:
Also, you can use "ApexPages.Severity.Warning" for another different level of severity.
Sorry Friend,
I missed the page information.
Regards,
Phanikumar
You cannot close the current window if it was NOT opened by javascript somewhere else because of security issues with your browsers. If you opened the current page with javascript all you need to do is:
Please add <apex:pageMessages/> after the <apex:form> tag. And please enclose your save method with a try-catch block like I post you as example.
How do you open the new window? Are you using a custom button for a record layout?
thx.