0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JavaScript: download系

Posted at

URL.createObjectURLURL.revokeObjectURLを組み合わせたdownloadの成功例と失敗例

自動

成功
let a=document.createElement("a");
a.download="a";
a.href=URL.createObjectURL(new Blob(["text"]));
a.click();
URL.revokeObjectURL(a.href)
失敗
let a=document.createElement("a");
a.download="a";
a.click(URL.revokeObjectURL(a.href=URL.createObjectURL(new Blob(["text"]))))
成功
let a=document.createElement("a");
URL.revokeObjectURL(a.href=URL.createObjectURL(new Blob(["text"])),a.click(a.download="a"))
//2回目は失敗
a.click()

手動

失敗
<a id=a download>DL</a><script>
a.onclick=()=>{
	a.href=URL.createObjectURL(new Blob(["text"]));
	URL.revokeObjectURL(a.href)
}
</script>
失敗
<a id=a download>DL</a><script>
a.onclick=()=>URL.revokeObjectURL(a.href=URL.createObjectURL(new Blob(["text"])))
</script>
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?