Open In App

HTML DOM Image crossOrigin Property

The HTML DOM Image crossOrigin property is used to set or return the value of the crossorigin attribute of the <img> element. This attribute is used to specify the HTTP CORS request when fetching or loading the stylesheet or icon files from the third-party server.

Syntax:



imgObject.crossOrigin;
imgObject.crossorigin="anonymous | use-credentials;

Property Values:  

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






<!DOCTYPE html>
<html>
 
<body>
    <center>
        <h1 style="color:green;">
            GeeksforGeeks
        </h1>
         
        <h2>DOM Image crossOrigin Property</h2>
 
        <img id="myImage" align="center" src=
            width="200" height="200"
            crossorigin="anonymous" />
        <br><br>
         
        <b>
            Click on the below button to return
            the crossorigin property
        </b>
        <br><br>
         
        <button onclick="btnClick()">
               Return
       </button>
         
       <h2 id="statusID" style="color:green;"></h2>
    </center>
     
    <script>
        function btnClick() {
            var txt = document.getElementById("myImage").crossOrigin;
            document.getElementById("statusID").innerHTML = txt;
        }
    </script>
</body>
 
</html>

Output:

 

Supported Browsers:


Article Tags :