vadnica-logo
X

The <crossorigin> Attribute

The <crossorigin> attribute specifies how the browser should perform a CORS request for a resource loaded from a DIFFERENT origin (different domain, subdomain, protocol, or port). This matters when loading scripts, styles, images, fonts, or video from external servers. CORS (Cross-Origin Resource Sharing) is a mechanism that defines the rules for whether and how resources can be shared across different origins. The <crossorigin> attribute has two main values:

  1. "anonymous": the request does not send credentials (cookies, Authorization). The server must return the Access-Control-Allow-Origin header (e.g., https://your-domain.com or *).
  2. "use-credentials": the request sends credentials. The server must return Access-Control-Allow-Origin: https://your-domain.com (not *) and Access-Control-Allow-Credentials: true.

If you load a resource from the same origin (e.g., src="/..."), the <crossorigin> attribute has no effect. For a practical example, prepare an external JavaScript file on another domain or subdomain and include it in your HTML document with the appropriate <crossorigin> attribute.

EXAMPLE
RESULT

Thank you for visiting! Adding privacy policy.

© 2024 All rights reserved.

Vam je koda pomagala? Če želite podpreti moj trud pri pripravi vodičev in vzdrževanju strani, mi lahko namenite donacijo za kavo.