HTML5 中 cross-origin 屬性的用法是什麼?


官方規範對 cross-origin 屬性的定義如下 −

The crossorigin attribute is a CORS settings attribute.
Its purpose is to allow images from third-party sites that allow
cross-origin access to be used with canvas.


當它與 CORS 頭部結合使用時,它將允許從外部來源載入的、由 <img> 元素定義的影像在 canvas 中使用。此過程就像從當前來源載入一樣。

你可以使用它來解決 JavaScript 錯誤,例如記錄 js 錯誤 −

if (securityOrigin()->canRequest(targetUrl)) {
   msg = myError;
   line = myLineNumber;
   source = sourceURL;
} else {
   msg = "Error!";
   source = String();
   line = 0;
}

更新於: 2020 年 6 月 24 日

206 次瀏覽

開啟您的 職業

完成該課程獲得認證

開始
廣告
© . All rights reserved.