
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to allow the restricted resources from another domain in web browser with HTML5
Cross-origin resource sharing (CORS) is a mechanism to allows the restricted resources from another domain in a web browser
For suppose, if you click on HTML5- video player in html5 demo sections. it will ask camera permission. if user allows 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
- Does HTML5 allow you to interact with local client files from within a web browser?
- How to check web browser support in HTML5
- Does HTML5 allow you to interact with local client files from within a browser?
- Implement Onclick in JavaScript and allow web browser to go back to previous page?
- How does selenium interact with the Web browser?
- How to set src to the img tag in HTML from another domain?
- How to store data in the browser with the HTML5 localStorage API?
- How to open a website in Android’s web browser from any application?
- Log error to console with Web Workers in HTML5
- With JavaScript how can I find the name of the web browser, with version?
- How to open a website in iOS's web browser from my application?
- Allow only access to camera device in HTML5
- How to handle errors in HTML5 Web Workers?
- Cross domain HTML5 iframe issue
- Difference between Web Browser and Web Server.

Advertisements