Data exchange between different domains (DOMAIN)

zhaozj2021-02-16  52

Data exchange between different domains (DOMAIN)

Introduction A problem is encountered when the original Web application is revised, and it needs to be extracted from the original application, and the original application interface is reserved with a more common application. . The original application belongs to the news.mycompany.com domain, and the new application will be deployed to UPLoad.myCopany.com. When I tried to pass data from the new domain to news.mycompany.com, I met the "Access Denied" error message returned by the browser in the front desk, found a large number of English materials found in Google. The problem of the problem, and the problem is partially resolved by specifying the docment.domain attribute in the two domains. Later, I quickly found the Chinese information related to Document.Domain in Google, but most of them were online security articles, and there were very few articles to refer to the Document.Domain property between the specified page. Between two domains. Data exchange, so decided to write this article, I hope to be able to throw the jade.

Keywords: JavaScript, Domain, Access Denied

Date: 2003-07-06

Problem The presentation often encounters the case where the data needs to be transmitted between the two frames is often encountered when developing a web application. The frames can be the frameset in the Frameset or a separate window. The common situation is a frame as an application, and another frame provides some options for users. After the user is selected, the frame sends the user to the server and passes some information to the main frame, here information It may be that the user's choice may also be the data returned by the server. When the content in the two frames is achieved, it has been simpler, but when they are divided into different domains, the problem becomes complicated and tricky, because the security issues of data access are involved, and they will not be good. An error message that is refused access (Access Denied) "returned by the browser.

Possible Solution Under We will analyze some methods of passing data between frames that belong to different domains.

Use client scripts (such as JavaScript) and window handles to transfer data between two frames to deliver data between two frames between two frames, transmit data by session.

Solution One Client Script Implementing Data Exchange between Two Frames should be one of the most lightweight ways, do not increase the load of the server does not occupy network bandwidth, data exchange is completely completed at the client . Let's first take a look at how to use the client script (as an example of JavaScript) and the window handle to implement data exchange within a domain.

We will explain by an instance: Suppose you need to provide users with a news entry interface, users can use it to enter the original content of the news, and can embed a pair in it. In order to achieve this function interface, we have designed two frames, or two windows:

Main window: The main editing interface of the news content, users can enter the news of the news, the author, news main body, etc., and one picture box can preview the uploaded image pop-up window: handle the interface uploaded, the user can choose local picture After uploading, after success, it returns the URL of the server to the main window to preview to the main window. We assume that the contents in the two windows are static. The files corresponding to the main window are newuseit.html, pop-up corresponding files. For imgupload.html (while the content of the two windows should be dynamically generated).

Where newsedit.html is located in the main directory of News.mycompany.com, the source code is as follows: