Scenario: When page A opens page B, after operating on page B, page A needs to synchronize the changed data Page A, http://127.0.0.1:10001/A.html var domain = 'http://127.0.0.1:10001'; window.open('http://127.0.0.1:10001/B.html'); window.addEventListener('message', function (event) { if (event.origin !== domain) return; console.log('message received: ' + event.data, event); }, false); B page, http://127.0.0.1:10001/B.html, opener is the reference to the opener of the current window var domain = 'http://127.0.0.1:10001'; window.opener.postMessage("success", domain); window.close(); If A needs to open B and send data to B at the same time // Sending data var domain = 'http://127.0.0.1:10001'; var myPopup = window.open('http://127.0.0.1:10001/B.html'); myPopup.postMessage('data', domain); // Receive data window.addEventListener('message', function(event) { if(event.origin !== 'http://127.0.0.1:10001') return; console.log('message received: ' + event.data,event); },false); The above is the details of how to use js to communicate between two html windows. For more information about js communication between two html windows, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Analyze Mysql transactions and data consistency processing issues
Table of contents Lifecycle Functions Common life...
Table of contents 1. Process 2. Core Architecture...
Table of contents Method 1: Call the function dir...
Table of contents Preface: 1. About data migratio...
Table of contents Modify the repository source st...
Related articles: Beginners learn some HTML tags ...
When writing a web project, I encountered an intr...
Table of contents 1. Introduction 2. filter() 3. ...
This article example shares the specific code of ...
Table of contents Preface Step 1: Setup and front...
1. Introduction When filtering unknown or partial...
Native JS implements the click number game for yo...
Setting the font for the entire site has always b...
Table of contents 1. Demo Project 1.1 Interface P...
Preface Still referring to the project mentioned ...