You need to sign in to do that
Don't have an account?
V1nit
Custom Button to close the window
I have created a custom button on a custom object called "Contact". which is of type "Onclick Execute JavaScript".
I have got "window.close()" in the button code.
I want to use this button on the Visualforce page.
Once the user clicks on the button, the browser window should close. Any ideas on how to use the custom button on the visualforce page ?
I can't see any way that you can access the custom links/buttons from the object definition, though I haven't looked that hard I must admit.
Is there any reason why you wouldn't just put a command button in the Visualforce page with onclick javascript?
I tried that as well. But, can you please share the CommandButton code we use to close the window using window.close() function.
This is the piece of code I am using at the moment.
<apex:commandButton action="window.close()" value="Close" onclick="window.close()"/>
You don't need the action attribute - that's only needed if you are executing a method in your controller.
The onclick should work when used that way - what behaviour are you seeing?
Thanks for that. I removed the action attribute and tried clicking on the button......The page just refreshed....Didn't close the window. Any alternative way to do this ?
Try:
window.close(); return false;
I think that the form submission will continue if there is no return value.
window.close() works best when used with a newly created window having a particular new name. I suggest you to use self.close(). I tried the same but couldn't reach to what you were asking for.
There is a security restriction on JavaScript that prevents a window from closing unless opened by JavaScript. I know that previously they used to popup a dialog box, but now I think it's just plain ignored unless it was opened by a script.