简体   繁体   中英

How to auto refresh previous page from popup form submission

I am trying to reload the previous page from where I opened a popup (a php file) with window.open function. I was able to close the popup with self.close() function, but previous page from where I opened the popup is not auto refreshing.

<script type='text/javascript'>
    location.replace(document.referrer);
    self.close();
</script>

You have window.opener . should work while it's not cross domain

window.opener.document.location.reload()

You can try the bellow code snippet to reload the main page on closing the pop up page.

<button onclick="myFunction()">Popup Page</button>


<script>
// -----POP SECTION-------
function myFunction() {
  window.open("http://localhost/popup_page.");
}
// -----END POP SECTION-------

// -------REFRESH PAGE ON POPUP CLOSE-----
var blurred = false;
window.onblur = function() { blurred = true; };
window.onfocus = function() { blurred && (location.reload()); };
// -------END REFRESH PAGE ON POPUP CLOSE-----
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM