解決canvas跨域問題(圖片,視頻資源跨域)


 
添加跨域條件   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,以后有一起討論,各種好組件)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM