Why does canvas.toDataURL() throw a security exception?

后端 未结 10 1519
天涯浪人
天涯浪人 2020-11-22 12:56

Did I not get enough sleep or what? This following code

var frame=document.getElementById(\"viewer\");
frame.width=100;
frame.height=100;

var ctx=frame.getC         


        
10条回答
  •  孤街浪徒
    2020-11-22 13:42

    I was able to make it work using this:

    Write this on first line of your .htaccess on your source server

    Header add Access-Control-Allow-Origin "*"
    

    Then when creating an element, do it as follows:

    // jQuery
    var img = $('')[0]
    
    // or pure
    var img = document.createElement('img');
    img.src='http://your_server/img.png';
    img.setAttribute('crossOrigin','anonymous');
    

提交回复
热议问题