Traditional Culture Encyclopedia - Weather inquiry - What does cross-domain mean?

What does cross-domain mean?

Question 1: What does cross-domain mean and what causes it? What are the solutions? Web front-end cross-domain knowledge refers to the mutual access between different domain names. For example, there are two servers on my computer,192.1192.168.0.12. If the page on the first server wants to visit the second server, it is called cross-domain.

There is a window.postMessage method in HTML5, which supports cross-domain access. Please refer to for details.

webhek/window-postmessage-api

If your program is on the server, you can also perform corresponding operations to complete cross-domain access.

If you have any questions about the pure hand tour, please consult.

Question: What is the difference between ajax cross-domain and non-cross-domain The advantage of cross-domain is that it can make full use of distributed cluster system, so that some service pressure can be dispersed to multiple servers. But it has a certain impact on the security of data interaction.

The advantage of not cross-domain is that the foreground page and background service are all under one server, which has high security, but it cannot share the load.

At present, the computer industry is developing in the direction of high integration, multi-concurrency and low coupling.

It is a good scheme that all basic services are provided in the form of interfaces (such as Baidu Map, WeChat and Alipay all have service interfaces), and the interaction between basic services and middleware may also be in the form of service invocation, which involves cross-domain. Handling the balance between cross-domain and security is one of the key aspects of this kind of integrated system.

Question 3: What do you mean by cross-domain in web pages? Simply put, you cross two domain names, such as the web page under Tencent domain name to the web page under Baidu, and cross-domain access.

Question 4: What is cross-domain access? Cross-domain access means that you access the content of another domain in one domain environment.

The premise of cross-domain access is mutual trust, otherwise it cannot be accessed.

Question: What does ajax mean across domains? Can you give a simple example to illustrate? Ajax requests a web resource whose destination address is not the local domain (protocol, domain name and port are different), and obtains external application data according to the response. For example, when we use Ajax to access public service interfaces such as city weather forecast and IP address, it involves cross-domain. When we request external services, the browser will refuse to grant access based on security issues. However, there is no cross-domain problem with the src attribute of script, script and iframe tags, so Ajax takes advantage of this and JSON support across domains. As long as you respond to Ajax requests with a piece of JSON code or JSON data, Ajax can get external services.

For example, jquery's getScript.

$. Before the callback function is executed, getscript(pv.sohu/cityjson, function(){ The js code of this service is returncitysn = {CID:110000, CIP: 124.xxx.22.xxx, AME. console . log(cid:+returncitysn . cid); console . log(CIP:+returncitysn . CIP); console . log(ame:+returnCitySName); });

Question 6: Why do some people say that ajax cannot cross domains? What do you mean you can't access it through ajax? Well, that means ajax can only be accessed under its own domain. For example, AJAX written by Tencent can't access things in Baidu. This is cross-domain! Using AJAX requires a server environment. At present, only Firefox can use AJAX directly without building an environment!

Question 7: What is cross-domain access? If we are on a website, we want to use Ajax to get the specific content in B website.

If website A and website B are not in the same domain, there will be cross-domain access problems.

Cross-domain access of Ajax is a common problem for existing Ajax developers.

Generally, jsoncallback method is used to solve it.

You can understand that it is not safe to send requests or request data between two domain names, otherwise it is not safe.

I hope it helps you.

Question 8: What do you mean by cross-domain in 8:js? You can refer to cors mechanism and p3p protocol. I forgot the specific content and code flow. If you need a specific process, please ask me, and I will help you look up the book.

Question 9: What is JS cross-domain access? In the address pointed by ajax or iframe, the second-level domain name, port and protocol must be exactly the same as the home page, otherwise it is cross-domain.

take for example

A. Baidu's visit to B. Baidu is cross-domain;

A. Baidu: 8080 access A. Baidu: 80 is cross-domain;

A. Baidu's visit to A. Baidu is cross-domain

Ajax cross-domain, there are two ways: the back-end writes proxy interface to let the back-end catch data; Or cooperate with the other party to transmit data through jsonp and other means.

There are a lot of cross-domain problems in iframe, and communication can only be carried out with the cooperation of iframe internal pages. There are many ways:

1, pseudo-writing hash value communication, the parent page and the child page respectively set polling to detect the hash value of the url in the iframe, and communicate through the value.

2. Use HTML5 postMessage, but note that this is also asynchronous.

3. Using the navigator bug in IE6\7, my former colleagues found that in ie6/7, the window.navigator used in parent-child pages is the same thing. If the parent page is changed, the child page will be changed accordingly.

4. An iframe is nested with a top-level page in the same domain, for example, A and B are nested, and B and C are nested, where A and C are in the same domain. After the modification of B, the value is passed to C through url, and the top object in C is also A, because it is in the same domain, so there will be no problem.

Question: What does jsonp cross-domain request mean in javascript development? What is cross-domain? Why use jsonp? The cross-domain is javascript. For security reasons, the browser is not allowed to call objects in other domain names pages from JavaScript in the currently visited domain name page.

Cross-domain request is to solve the problem of prohibiting cross-domain access.

Jsonp is used because json is an object in javascript, and there is no restriction on cross-domain access of pictures, css, javascript script files, etc. Therefore, you can dynamically set the src path in the tag when rendering the page, and the path is returned to the json object.