canvas.toDataURL image/png error handling method recommendation

canvas.toDataURL image/png error handling method recommendation

Problem background:

There is a requirement to take a screenshot of the playing video. The video is played using the video tag, and then a real-time frame image is captured when the video playing area is clicked.

The code is very simple as follows:

JavaScript CodeCopy content to clipboard
  1. var video = document.getElementById( 'video' );
  2.   
  3. var canvas = document.getElementById( 'canvas' );
  4.   
  5. var ctx = canvas.getContext( '2d' );
  6.   
  7. var img = document.getElementById( 'img' );
  8.   
  9. function snapshot() {
  10. ctx.drawImage(video,0,0);
  11. img.src = canvas.toDataURL( 'image/png' );
  12. }
  13.   
  14. video.addEventListener( 'click' , snapshot, false );

Questions:

Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

After checking and analyzing, we found that this was actually because the domain where the video file was located was different from the domain where the picture and page were located, resulting in a cross-domain transmission problem.

Solution:

Place the video file under the domain where the page is located.

Original address: http://blog.csdn.net/luochao_tj/article/details/44942125

<<:  mysql wildcard (sql advanced filtering)

>>:  IE6/7 is going to be a mess: empty text node height issue

Recommend

W3C Tutorial (3): W3C HTML Activities

HTML is a hybrid language used for publishing on ...

Several ways to use v-bind binding with Class and Style in Vue

Adding/removing classes to elements is a very com...

Prevent HTML and JSP pages from being cached and re-fetched from the web server

After the user logs out, if the back button on the...

Implementation of Vue single file component

I recently read about vue. I found a single-file ...

Detailed explanation of common methods of JavaScript Array

Table of contents Methods that do not change the ...

Specific method of viewing user authorization information in mysql

Specific method: 1. Open Command Prompt 2. Enter ...

HTML+CSS to achieve simple navigation bar function

Without further ado, I'll go straight to the ...

SQL Aggregation, Grouping, and Sorting

Table of contents 1. Aggregate Query 1. COUNT fun...

Detailed explanation of vue page state persistence

Table of contents Code: Replenish: Summarize Requ...

Markup Languages ​​- What to learn after learning HTML?

Click here to return to the 123WORDPRESS.COM HTML ...

HTML table tag tutorial (26): cell tag

The attributes of the <TD> tag are used to ...

Use iptables and firewalld tools to manage Linux firewall connection rules

Firewall A firewall is a set of rules. When a pac...

Records of using ssh commands on Windows 8

1. Open the virtual machine and git bash window a...

Solution to Apache cross-domain resource access error

In many cases, large and medium-sized websites wi...