Skip to content
Related Articles

Related Articles

HTML DOM Script crossOrigin Property

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 12 Apr, 2022

HTML DOM Script crossOrigin property is used to set or return the value of the crossOrigin attribute of the <script> element. This attribute is used for specifying the HTTP CORS request when fetching or loading the stylesheet or javascript files from the third-party server.

Syntax:

  • It returns the cross-origin property.
scriptObject.crossOrigin;
  • It is used to set the cross-origin property.
scriptObject.crossorigin="anonymous | use-credentials;  

Property Values:

  • anonymous: It has a default value. It defines that 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.     

Example: Below HTML code returns the script cross-origin property.  

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        DOM script crossOrigin Property
    </title>
</head>
  
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>
        DOM script crossOrigin property
    </h2>
  
    <script id="myGeeks" type="text/javascript" 
        src="my_script.js" crossorigin="anonymous">
    </script>
    <br>
  
    <button onclick="Geeks()">Submit</button>
  
    <h2 id="demo"></h2>
  
    <script>
        function Geeks() {
            var x = document.getElementById(
                "myGeeks").crossOrigin;
            document.getElementById(
                "demo").innerHTML = x;
        }
    </script>
</body>
  
</html>

Output 

 

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!