• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Screenshot button of frame

Explorer ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

In my online html5 canvas game I want the user to be able to download the score of the game as an image. In the forum I've found a script that works very good!

 

_this.DownloadReset.SaveImage.on('click', function(){
var aTag = document.createElement('a');

aTag.setAttribute('href', canvas.toDataURL("image/png"));

aTag.innerHTML = "Download";

aTag.download = "This_is_your_story.png";

document.body.appendChild(aTag);
});

 

But I actually want the user to download it with a button within my interface. This shows a download text outside of the div. Is there a easy fix for that? Instance name of my button is "SaveImage".

 

Screenshot 2021-03-24 at 15.33.35.png

Views

326

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 24, 2021 Mar 24, 2021

 

 

_this.DownloadReset.SaveImage.on('click', function(){
var aTag = document.createElement('a');

aTag.setAttribute('href', canvas.toDataURL("image/png"));

aTag.innerHTML = "Download";

aTag.download = "This_is_your_story.png";

aTag.click()
});

 

 

Votes

Translate

Translate
Community Expert ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

 

 

_this.DownloadReset.SaveImage.on('click', function(){
var aTag = document.createElement('a');

aTag.setAttribute('href', canvas.toDataURL("image/png"));

aTag.innerHTML = "Download";

aTag.download = "This_is_your_story.png";

aTag.click()
});

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Fantastic. thank you for your swift reply!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines