This article mainly introduces the relevant information on the method of using postMessage to implement Ajax cross-domain requests in HTML5. Friends who need it can refer to it
Due to the limitation of homologous policies, Javascript has problems with cross-domain communication, and typical cross-domain problems include communication between iframe and parent.
Several common solutions:(1) document.domain+iframe;
(2) Dynamically create scripts;
(3) iframe+location.hash;
(4) flash.
I won't go into details about these methods here, but the window.postMessage of HTML5 is recorded.
postMessage is compatible with IE8+, Firefox, Opera, Safari, and Chrome.
Two foreign servers are needed for testing, and of course local and online servers can also be used as two foreign servers.
If developed using phonegap, you can install the request file on the client, and then dynamically request the server's data processing to obtain and display the data. In this way, you can use any web development language and methods to develop the backend required for phonegap app.
1. Usage of postMessagepostMessage is a new API introduced by HTML5 to solve the problem of cross-domain of js, allowing multiple iframes/windomain communication.
Assume that there is a structure as follows:
JavaScript Code Copy content to clipboard