?
This document uses PHP Chinese website manual Release
在HTML5中,一些 HTML 元素提供了對(duì) CORS 的支持, 例如<img>
和 <video>
均有一個(gè)跨域?qū)傩?nbsp;(crossOrigin
property),它允許你配置元素獲取數(shù)據(jù)的 CORS 請(qǐng)求。 這些屬性是枚舉的,并具有以下可能的值:
關(guān)鍵詞 | 描述 |
---|---|
匿名 | 此元素的CORS請(qǐng)求將不會(huì)設(shè)置憑證標(biāo)志。 |
使用的憑據(jù) | 此元素的CORS請(qǐng)求將設(shè)置憑證標(biāo)志; 這意味著請(qǐng)求將提供憑據(jù)。 |
默認(rèn)情況下 (即未指定crossO
rigin屬性時(shí)), CORS 根本不會(huì)使用。如Terminology section of the CORS specification 中的描述, “anonymous" 關(guān)鍵字說(shuō)明不會(huì)通過(guò) cookies,客戶端 SSL 證書(shū)或 HTTP 認(rèn)證交換用戶憑據(jù)。
即使是無(wú)效的關(guān)鍵字和空字符串也會(huì)被當(dāng)作 anonymous
關(guān)鍵字使用。
你可以使用下面的<script>
元素告訴一個(gè)瀏覽器執(zhí)行來(lái)自 https://example.com/example-framework.js
的腳本而不發(fā)送用戶憑據(jù)。
<script src="https://example.com/example-framework.js" crossorigin="anonymous"></script>
規(guī)范 | 狀態(tài) | 評(píng)論 |
---|---|---|
HTML Living Standard該規(guī)范中'CORS設(shè)置屬性'的定義。 | 生活水平 | |
HTML生活標(biāo)準(zhǔn)該規(guī)范中'跨部門(mén)'的定義。 | 生活水平 |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 13 | 8.0 (8.0) | 11 | No support | (Yes) |
<video> | ? | 12.0 (12.0) | ? | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 8.0 (8.0) | ? | ? | (Yes) |
<video> | ? | 12.0 (12.0) | ? | ? | ? |