WebSocket solve JavaScript cross-domain problem with a dose of medicine

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.