How to use js to communicate between two HTML windows


Scenario: when page a opens page B, and page a needs to synchronize the changed data after the operation of page B

Page a,

var domain = '';'');
window.addEventListener('message', function (event) {
    if (event.origin !== domain) return;
    console.log('message received:  ' +, event);
}, false);

Page B, , opener is the opener reference of the current window

var domain = '';
window.opener.postMessage("success", domain);

If a needs to open B and send data to B

//Send data from
var domain = '';
var myPopup ='');
myPopup. PostMessage ('data ', domain);

//Receiving data party
window.addEventListener('message', function(event) {
    if(event.origin !== '') return;
    console.log('message received:  ' +,event);

The above is the details of how to use js to communicate between two HTML windows. For more information about JS communicating between two HTML windows, please pay attention to other developeppaer related articles!