Javascript: Close popup

I have a button on the main page that will open (window.open ()) the W1 window to allow the user to select material on it. After that, press the OK button on W1 to open the W2 window (again window.open ()). How can I close W1 after the user clicks OK?

+4
source share
2 answers

Use the window.close() method with the name of the target window, as shown below:

 win1 = window.open("","","width=100,height=100"); okBtn.onclick = function() { win2 = window.open("","","width=100,height=100"); win1.close(); } 
+3
source

On the main page, you save the popup in W1 and define a function that closes W1:

 W1 = window.open("","","width=100,height=100"); function closeW1() { W1.close(); } 

Now on W1 in the same place where you open W2:

 okBtn.onclick = function() { W2 = window.open("","","width=100,height=100"); window.opener.closeW1(); } 

What is it. Everything is ready.

0
source

Source: https://habr.com/ru/post/1395140/


All Articles