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 8226977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:57:45+00:00 2026-06-07T15:57:45+00:00

I am trying to draw a canvas created through javascript on another canvas. But

  • 0

I am trying to draw a canvas created through javascript on another canvas. But it is not working for me,

Here is my code,

    <!DOCTYPE HTML>
<html>
  <head>
    </script>
       <script>
        window.onload = function(){  
        var can1 = document.createElement('canvas');
        can1.width = 150;
        can1.height = 140;
        can1.style.cssText = 'top:2px;left:2px;border:2px  solid black;';

        var ctx1 = can1.getContext('2d');
        var img=new Image();
        img.src="images/211.jpg"
        ctx1.drawImage(img,0,0);

        var can = document.getElementById("c");
        var ctx = can.getContext('2d');
        ctx.drawImage(can1,0,0);
        var canvas =  document.getElementById("c"); 
        window.open(canvas.toDataURL());
        }

    </script>
</head>
<body >
    <canvas id="c" style = "position:absolute;top:150px;width:250px;height:350px;left:500px; border:2px  solid black;"></canvas>
</body>
</html>
  • 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-07T15:57:47+00:00Added an answer on June 7, 2026 at 3:57 pm

    I think the problem was that, when you were trying to drawImage that image into the canvas, image was not ready. so if u do this it works perfectly:

    <!DOCTYPE HTML>
    <html>
      <head>
        <style>
          body {
            margin: 0px;
            padding: 0px;
          }
          #myCanvas {
            border: 1px solid #9C9898;
          }
        </style>
        <script>
          window.onload = function() {
    
            var imageObj = new Image();
            imageObj.src = "http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg";
    
            var dynamicCanvas = document.createElement("canvas");
            var dynamicContext = dynamicCanvas.getContext("2d");
            dynamicCanvas .height="400";
            dynamicCanvas.width="578";
    
            var canvas = document.getElementById("myCanvas");
            var context = canvas.getContext("2d");
    
            imageObj.onload = function() {
              dynamicContext.drawImage(imageObj, 69, 50);
              context=context.drawImage(dynamicCanvas,69,50);
              window.open(canvas.toDataURL());
            };
          };
    
        </script>
      </head>
      <body>
        <canvas id="myCanvas" width="578" height="400"></canvas>
      </body>
    </html>
    

    and you can adjust the height and width of the dynamic canvas.

    if you remove that window.open statement, its perfect.

    but there is a problem with canvas.toDataURL()

    when you try to do canvas.toDataURL() for a local file, it gives a security error (if you inspect it through google chrome) i.e.

    Uncaught Error: SECURITY_ERR: DOM Exception 18 
    

    you can know more about this error : here
    (see if you are getting this error). anyways, the root cause is sorted out, and there’s a new problem now altogether :D..anyways better luck!!

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

Sidebar

Related Questions

I'm trying draw canvas on a new one but not only to draw it,
I am trying to draw on a html5 canvas and the following code should
I am trying to draw a red rectangle on my HTML5 canvas. Here is
I'm trying to draw text using canvas. I checked out everywhere but those examples
I am trying to draw over a canvas by clicking and dragging the mouse.
I am trying to draw in a web worker using html5 canvas. The worker
I am trying to draw a series of images on an HTML5 Canvas .
I'm trying to draw over the whole screen by using the desktop canvas and
I am trying to use the HTML5 canvas element to draw some arcs and
I am trying to draw a box in a console but I cant figure

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.