Home>Article>Backend Development> Five solutions for website cross-domain

Five solutions for website cross-domain

little bottle
little bottle forward
2019-04-30 13:50:35 5147browse

Because the browser uses the same-origin policy, a cross-domain request occurs. A webpage requests resources from another webpage with a different domain name/different protocol/different port. This is cross-domain. This article provides 5 ways to solve the problem of website cross-domain. Friends who are interested can take a look.

1. What is leapfrog?

  • A webpage requests resources from another webpage with a different domain name/different protocol/different port. This is cross-domain.
  • Cross-domain reason: In the current domain name request website, sending other domain names through ajax requests is not allowed by default.

2. Why does a cross-domain request occur?

  • Because the browser uses the same-origin policy

3. What is the same-origin policy?

  • The same-origin policy is a well-known security policy proposed by Netscape. All browsers that support JavaScript now use this policy. The same-origin policy is the core and most basic security function of the browser. If the same-origin policy is missing, the normal functions of the browser may be affected. It can be said that the web is built on the basis of the same-origin policy, and the browser is just an implementation of the same-origin policy.

4. Why does the browser use the same-origin policy?

  • is to ensure the security of user information and prevent malicious websites from stealing data. If the web pages do not meet the same origin requirements, they will not be able to:

    • 1. Sharing Cookies, LocalStorage, IndexDB
    • 2. Obtaining DOM
    • 3. AJAX requests cannot be sent

The non-absolute nature of the same-origin policy: