31
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Javascript】ボタンを押すとcanvasを画像としてダウンロード

Last updated at Posted at 2018-05-07

#概要
この記事では、HTMLのボタンを押すと、canvasを画像としてダウンロードできるようになるソースを紹介しています。

#ソース

<canvas id="canvas"><canvas>
<button id="download">download</button>
document.getElementById("download").onclick = (event) => {
	let canvas = document.getElementById("canvas");

	let link = document.createElement("a");
	link.href = canvas.toDataURL("image/png");
	link.download = "test.png";
	link.click();
}
31
29
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?