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

What you need to know about responsive design

Responsive design is to perform corresponding ope...

Ansible automated operation and maintenance deployment method for Linux system

Ansible is a new automated operation and maintena...

Importance of background color declaration when writing styles

As the title says, otherwise when the page is revi...

Implementation of Docker container connection and communication

Port mapping is not the only way to connect Docke...

Introduction to local components in Vue

In Vue, we can define (register) local components...

Web page html special symbols html special characters comparison table

Special symbols Named Entities Decimal encoding S...

How to deploy FastDFS in Docker

Install fastdfs on Docker Mount directory -v /e/f...

How to achieve the maximum number of connections in mysql

Table of contents What is the reason for the sudd...

Detailed steps to install web server using Apache httpd2.4.37 on centos8

Step 1: yum install httpd -y #Install httpd servi...

How to implement adaptive container with equal aspect ratio using CSS

When developing a mobile page recently, I encount...

Building a Redis cluster on Docker

Table of contents 1. Pull the image 2. Create a R...

MySQL 5.7.18 free installation version configuration tutorial

MySQL 5.7.18 free installation version installati...

MySQL column to row conversion and year-month grouping example

As shown below: SELECT count(DISTINCT(a.rect_id))...