Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to refresh parent page on closing a popup ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we are given the task to refresh the parent page by closing a popup.

Approach: The Steps to achieve this are as follows:

  • Create a page.
  • Create a popup.
  • Popup should contain a button that when clicked refreshes the parent page.
  • Attach an event listener to that button and listen for the click event on that button.
  • Clicking on that button triggers a function that reloads the parent page.

Reloading is achieved by JavaScript using the below statement

The location.reload() method in HTML DOM is used to reload a current page document, this method refreshes the current document.



Note: Use internal CSS to make the page look beautiful. And all CSS code is within <style> tag.

Example: This example uses the above-explained approach.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
    <title> Refresh Example </title>
    <!-- Create a simple web page -->
        <h1>Refresh Example </h1>
        <button class="btn" id="popup-btn">
            Show popup
    <!-- Create a simple popup which is hidden using CSS -->
    <div id="wrapper">
        <div id="popup">
                <button class="btn" id="close-btn">


/* Css Styling */
h1 {
    font-size: 45px;
    font-family: 'Courier New',
    text-align: center;
.btn {
    padding: 10px 20px;
    font-size: 24px;
    background-color: #0f9d58;
    border: none;
    color: white;
    border-radius: 10px;
    outline: none;
    box-shadow: 0px 3px 2px 1px rgb(100, 100, 100);
    cursor: pointer;
#popup-btn {
    margin-left: 45%;
#wrapper {
    position: absolute;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(100, 100, 100, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    visibility: hidden;
#popup {
    width: 50%;
    height: 50%;
    background-color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
h2 {
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    font-size: 40px;


// Attach event listener to open popup
    'popup-btn').addEventListener('click', (e) => {
            'wrapper').style.visibility = "visible";
// Attach event listener to first close popup and then refresh page
    'close-btn').addEventListener('click', (e) => {
            'wrapper').style.visibility = "hidden";

Output: Click here to check the live Output.


My Personal Notes arrow_drop_up
Last Updated : 25 Apr, 2023
Like Article
Save Article
Similar Reads
Related Tutorials