How to open popup and refresh the parent page on close popup with JavaScript?

You can achieve this by opening the popup window with window.open() and then attaching an event listener to the popup window to detect when it is closed.

When the popup window is closed, you can refresh the parent page using window.location.reload().

Here’s how you can do it:

// Open the popup window
var popup = window.open('popup.html', 'popupWindow', 'width=600,height=400');

// Attach an event listener to detect when the popup is closed
if (popup) {
    popup.addEventListener('unload', function() {
        // Refresh the parent page when the popup is closed
        window.opener.location.reload();
    });
} else {
    // Handle the case when the popup blocker prevents the popup from opening
    alert('Popup blocked! Please allow popups to continue.');
}

Make sure to replace 'popup.html' with the URL of your popup window. This code assumes that both the parent page and the popup window are served from the same domain to avoid cross-origin issues. If they are served from different domains, you may encounter security restrictions.

Also, note that some browsers may block popups by default, so the user may need to allow popups for this to work.