1. 程式人生 > >Failed to execute 'toDataURL' on 'HTMLCanvasElement,在canvas.toDataURL()執行時候報錯解決方案

Failed to execute 'toDataURL' on 'HTMLCanvasElement,在canvas.toDataURL()執行時候報錯解決方案

from info long allow 條件 star The cross can

添加跨域條件 crossorigin="anonymous"

【Redirect at origin ‘http://xxx.xx.com‘ has been blocked from loading by Cross-Origin Resource Sharing

policy: No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘http://sub2.xx.com‘ is therefore not allowed access.】

技術分享圖片

var img =
new Image; img.onload = myLoader; img.crossOrigin = ‘anonymous‘; //可選值:anonymous,* img.src = ‘http://....‘;

或者是HTML中 <img src="" id="" crossorigin="anonymous">

視頻的話同上,<video width="320" height="240" controls="controls" crossorigin="anonymous"></video>

如果視頻 video.crossOrigin =

‘anonymous‘; 報錯的話,可以在標簽上面加該屬性。

個人博客 :很多好用的 npm 包 , 可以看看 https://gilea.cn/ 

github: https://github.com/longfei59418888/vui (很不錯的vue2.0組件庫,記得給一個 start,以後有一起討論,各種好組件)

Failed to execute 'toDataURL' on 'HTMLCanvasElement,在canvas.toDataURL()執行時候報錯解決方案