Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

Tags: popup parent

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.

The post How to open popup and refresh the parent page on close popup with JavaScript? appeared first on The Web Dev.



This post first appeared on The Web Dev, please read the originial post: here

Share the post

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

×

Subscribe to The Web Dev

Get updates delivered right to your inbox!

Thank you for your subscription

×