Its working, when preview button clicks page will be open and close button clicks its working. but i copied page url and paste in another tab, close button clicks its not working.

      <apex:commandbutton onClick="window.top.close();" value="Close"  />

1 Answer 1


JavaScript can only close a window opened by JavaScript. This is a security feature. You can read more about that on MDN's Window.close:

In the past, when you called the window object's close() method directly, rather than calling close() on a window instance, the browser closed the frontmost window, whether your script created that window or not. This is no longer the case; for security reasons, scripts are no longer allowed to close windows they didn't open. (Firefox 46.0.1: scripts can not close windows, they had not opened)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .