<apex:commandButton value="Search Again" onclick="return window.open('/apex/customreport');window.top.close();" />

it is opening one new window and the old window is also there .

when the button is clicked it has to close the current window and open the new window which i wrote above .answer would be great helpful

closed as unclear what you're asking by bigassforce, Matt Lacey Feb 25 '14 at 5:14

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • why would you want it? why not just update the current window link/URL? Can you detail more on the reason/logic that this is needed in such a way? – Saariko Feb 11 '14 at 14:22

You can replace "window.top.close()" with just "window.close()". It should work with IE & Chrome.

window.close() - is JavaScript function to close current window. But it's implementation is browser specific. It may not in Firefox if window is not created by JavaScript itself.

  • yeah javascript is only supposed to be allowed to close windows opened by javascript. It is able to do it even if they weren't in some browsers but not all. – Phil B Feb 11 '14 at 15:34

Make sure you specify the name on both windows. If they share the same name, then when you open one with the same name it will replace it.

apex:commandButton value="Search Again" onclick="window.open('/apex/customreport', 'myexample');" />

Not the answer you're looking for? Browse other questions tagged or ask your own question.