- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
CORS in HTML5
Cross-origin resource sharing (CORS) is a mechanism to allows the restricted resources from another domain in web browser
For suppose, if you click on HTML5- video player in html5 demo sections. it will ask camera permission. if user allow the permission then only it will open the camera or else it doesn't open the camera for web applications
Here Chrome, Firefox, Opera and Safari all use the XMLHttprequest2 object and Internet Explorer uses the similar XDomainRequest object, object.
function createCORSRequest(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { // Check if the XMLHttpRequest object has a "withCredentials" property. // "withCredentials" only exists on XMLHTTPRequest2 objects. xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { // Otherwise, check if XDomainRequest. // XDomainRequest only exists in IE, and is IE's way of making CORS requests. xhr = new XDomainRequest(); xhr.open(method, url); } else { // Otherwise, CORS is not supported by the browser. xhr = null; } return xhr; } var xhr = createCORSRequest('GET', url); if (!xhr) { throw new Error('CORS not supported'); }
- Related Articles
- Example of Event Handlers in HTML5 CORS
- How to resolve CORS issue in C# ASP.NET WebAPI?
- IndexedDB in HTML5
- MediaStream in HTML5
- Microdata API in HTML5
- WebSockets Attributes in HTML5
- URL Encoding in HTML5
- DataTransfer object in HTML5
- HTML5 tag
- HTML5 Semantics
- HTML5 Geolocation in Safari 5
- Stop Web Workers in HTML5
- Example of MathML in HTML5
- Input type URL in HTML5
- Example of createSignalingChannel() in HTML5

Advertisements