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

Analysis of the process of implementing Nginx+Tomcat cluster under Windwos

Introduction: Nginx (pronounced the same as engin...

Summary of the use of Vue computed properties and listeners

1. Computed properties and listeners 1.1 Computed...

WeChat Mini Program Lottery Number Generator

This article shares the specific code of the WeCh...

How to enable the slow query log function in MySQL

The MySQL slow query log is very useful for track...

How to reset the root password in Linux mysql-5.6

1. Check whether the MySQL service is started. If...

Elementui exports data to xlsx and excel tables

Recently, I learned about the Vue project and cam...

How to implement two-way binding function in vue.js with pure JS

Table of contents First, let's talk about the...

Examples of clearfix and clear

This article mainly explains how to use clearfix a...

First experience of creating text with javascript Three.js

Table of contents Effect Start creating text Firs...

Vue echarts realizes horizontal bar chart

This article shares the specific code of vue echa...

Example method to view the IP address connected to MySQL

Specific method: First open the command prompt; T...

VMware Workstation virtual machine installation operation method

Virtual machines are very convenient testing soft...

Floating menu, can achieve up and down scrolling effect

The code can be further streamlined, but due to t...

Detailed explanation of how to install MySQL on Alibaba Cloud

As a lightweight open source database, MySQL is w...