Recently I encountered JavaScript cross-domain problem in the project, the parent page and the child page to communicate, and the parent-child page cross-domain, how to do?
Everyone combined with previous experience, think of websocket,websocket client programming is relatively simple, the server we use Java implementation,
To ensure that parent-child page communication is a peer-to-peer project, it is necessary to establish a correspondence between parent and child page WebSocket on the server.
Page sent messages only quilt page received, sub-page messages are only received by the parent page we did the following work, Strictly guaranteed
WebSocket Communication is a point-to-point:
The first is to establish the URL of the WebSocket link plus a timestamp to ensure that the communication session is unique;
The second is to ensure that the parent-child page WebSocket one by one correspondence on the server. The websocket of the parent-child page will be
Send a message to the server to register and establish a correspondence between the senssion. The parent-child page is then available through a mutually binding
Communication with the letter agreement.
Baidu a bit, on-line service to introduce WebSocket programming is mass, we have been properly modified to meet the project
's needs.
WebSocket solve JavaScript cross-domain problem with a dose of medicine