HTML DOM Image crossOrigin Property
Last Updated :
20 Jun, 2022
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:
- It returns the cross-origin property.
imgObject.crossOrigin;
- It is used to set the cross-origin property.
imgObject.crossorigin="anonymous | use-credentials;
Property Values:
- anonymous: It has a default value. It defines a CORS request that 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 image cross-origin property.
HTML
<!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:
- Google Chrome
- Internet Explorer
- Firefox
- Apple Safari
- Opera
Share your thoughts in the comments
Please Login to comment...