JS implements a way to refresh the parent page without popping up a prompt box

  • 2021-06-29 10:10:01
  • OfStack

This article provides an example of how JS can refresh a parent page without popping up a prompt box.Share it for your reference, as follows:

A page open way out of the B page, when the B page has done a class such as save action, need to close the B page, refresh the A page, will pop up a prompt box, request to try again, this is unexpected, user experience is poor.

There are two scenarios for the solution:

1. Simple case of A page (no frame/iframe)

In function on the B page:


function close(){
 window.opener.location.reload();
 window.opener = null;
 window.open('','_self');
 window.close();
}

That's it.

2. The A page elements are a bit complex with frames, etc.

Requirement: The B page wants to refresh the A page

function in A page is called directly from function in B page, with the most common A as the list page and B as the new page:

There is a query button on the A page to find all the lists. We can trigger this function in the B page:


function close(){
 window.opener.queryAll(); //queryAll() by A Queries on Pages function
 window.close();
}

Note that if frame A jumps to frameB on the same page, it is not opener, but parent

More readers interested in JavaScript-related content can view this site's topics: Summary of JavaScript Switching Effects and Techniques, Summary of JavaScript Finding Algorithmic Techniques, Summary of JavaScript Animation Effects and Techniques, Summary of JavaScript Errors and Debugging Techniques, Summary of JavaScript Data Structure and Algorithmic Techniques.Summary of JavaScript Traversal Algorithms and Techniques and Summary of JavaScript Mathematical Usage

I hope that the description in this paper will be helpful to everyone's JavaScript program design.


Related articles: