Open In App
Related Articles

HTML <script> crossorigin Attribute

Improve Article
Save Article
Like Article

The HTML <script> crossorigin Attribute is used for loading an external script into their domain from a third party server or another domain with the support of HTTP CORS Request. This attribute is used to protect sensitive information from the third party when fetching out the results.

Cross-Origin Resource Sharing(CORS) is a tool that allows web pages requesting for resources from another domain that is outside of their own domain. It is also used for managing cross-origin requests which is a request for a resource from an outside domain.


<script crossorigin="anonymous | use-credentials">

Attribute Values:

  • anonymous: It has a default value. It defines a CORS request will be sent without passing the credentials information.
  • use-credentials: A cross-origin request will be sent with credentials, cookies, and certificate.

Note: This attribute is only valid for use if we try to fetch the resources from the third party domain. 

Example: Below code illustrates the use of crossorigin attribute with the <script> element. 


<!DOCTYPE html>
    <title>HTML script crossorigin Attribute</title>
<body style="text-align: center">
    <h2>HTML script crossorigin Attribute</h2>
    <br />
    <script type="text/javascript"
        src="my_script.js" crossorigin="anonymous">


Supported Browsers:

  • Google Chrome 30.0 and above
  • Internet Explorer not supported
  • Firefox 13.0 and above
  • Microsoft Edge 18.0 and above
  • Opera 12.0 and above
  • Safari 
Last Updated : 28 Jul, 2022
Like Article
Save Article
Similar Reads
Related Tutorials