Have a custom button and trying to open external link on button click. It works fine. But I would like to check if the window is already open and if yes, donot open another window:

right now i have (on button click) > Execute Javascript : enter image description here


I tried to add function to check if window is already open as below:

var isOpen = "false";
function OpenPopup()
   if(isOpen == "false")
         isOpen = "true"; 

But seems like I cannot use function inside as the onclick is not working after changing the code. First alert works but the one inside function is not working.

1 Answer 1


If you give the window a name when opening it initially then it will not open a new window:


However it will refresh the window...

This works as you would expect and does not reopen the window:

<apex:page >

var isOpen = false;

function OpenPopup()

   if(isOpen == false)
         isOpen = true; 
       alert('Already Opened');

<button onclick="OpenPopup(); return false;">Click me</button>


Having the name in the window.open ensure that if the refresh the VF page and click it again, it will just refresh the previously opened window instead of opening a new one

  • Thanks Eric. The first solution, window.open with name is working fine for all websites but for some reason, it is not working on our internal web address ..
    – sf_user
    Sep 2, 2015 at 18:10
  • 1
    @pmvsdt - That is a different question that what you originally posted. Please start a new question to troubleshoot that
    – Eric
    Sep 2, 2015 at 18:27

You must log in to answer this question.

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