Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:06:31+00:00 2026-06-14T12:06:31+00:00

I am trying to make work a button that would open a new window

  • 0

I am trying to make work a button that would open a new window with the content of my canvas in it (a rendered image of the canvas).

Here’s my JS code :

var canvas  = document.getElementById("thecanvas");
var dataUrl = canvas.toDataURL();
var context = canvas.getContext("2d");
context.fillStyle = "rgba(0, 0, 255, .5)";
context.fillRect(25, 25, 125, 125);
function clickme() {
window.open(dataUrl, "toDataURL() image", "width=200, height=500");
}​

HTML code :

<input type="button" onclick="clickme()" value="OPEN"/>

<canvas id="thecanvas" height="200" width="500" style="border:1px solid black"> 

But when I click on the “OPEN” button, nothing happens…but I really don’t see why. I have looked on alot of sites for tutorials. I even copied and pasted some codes, but still nothing happens. Am I doing something wrong? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:06:31+00:00Added an answer on June 14, 2026 at 12:06 pm

    First off, the order in which you execute your statements matters. You need to call toDataURL after you draw to the canvas, or the dataURL generated with not contain that content.

    I’m not sure what your script tags are like, but here’s a working example that does the event in a slightly more foolproof way: http://jsfiddle.net/b7G6J/

    HTML:

    <input id="thebutton" type="button" value="OPEN"/>
    
    <canvas id="thecanvas" height="200" width="500" style="border:1px solid black"> 
    

    JS:

    var canvas  = document.getElementById("thecanvas");
    var context = canvas.getContext("2d");
    
    // First drawing commands
    context.fillStyle = "rgba(0, 0, 255, .5)";
    context.fillRect(25, 25, 125, 125);
    // Then toDataURL
    var dataUrl = canvas.toDataURL();
    
    var button = document.getElementById("thebutton");
    button.onclick =function() {
      window.open(dataUrl, "toDataURL() image", "width=200, height=500");
    }
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i've got a Code with Python and i'm trying to make it work
i am trying to make the preloading work in such a way that the
I'm trying to make a regular button that functions like a toggle button, but
I'm trying to make a class that would draw objects of my JBox2d's world
I'm trying to make a button that basically mimics the buttons seen on the
Trying to make a simple scroll to top button that smoothly scrolls up and
I'm trying to render a button that should be initially rendered disabled and at
I'm trying to make a button that changes two things with CSS. First, it
I am trying to make aSmack work in my project. Created a standard project
I'm trying to make resque work with heroku. It works with my other application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.