HTML5中的CORS
跨域资源共享(CORS)是一种允许来自Web浏览器中另一个域的受限资源的机制
假设,如果您在html5演示部分中单击HTML5-视频播放器。它将询问相机许可。如果用户允许该权限,则仅会打开摄像头,否则不会为网络应用程序打开摄像头
在这里,Chrome,Firefox,Opera和Safari都使用XMLHttprequest2对象,而InternetExplorer使用类似的XDomainRequest对象。
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") {
//否则,检查XDomainRequest。
//XDomainRequest仅存在于IE中,并且是IE发出CORS请求的方式。
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
//否则,浏览器不支持CORS。
xhr = null;
}
return xhr;
}
var xhr = createCORSRequest('GET', url);
if (!xhr) {
throw new Error('CORS not supported');
}热门推荐
2 训练狗狗成为
3 训练狗狗几岁
4 反应训练狗狗
5 听力训练狗狗
7 狗狗尿训练
8 拳击训练狗狗
10 狗狗训练卧室
11 一个月狗狗怎么训练
12 几个月训练狗狗大小便
13 牧羊犬训练狗狗
14 狗狗训练做
15 狗狗训练它
16 可以训练狗狗
17 训练狗狗给球
18 训练狗狗的技巧