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

  • Home
  • SEARCH
  • 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 7071223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:39:43+00:00 2026-05-28T05:39:43+00:00

This is the code, (don’t kill me, i’ve just started to study javascript)…Firefox’errors console

  • 0

This is the code, (don’t kill me, i’ve just started to study javascript)…Firefox’errors console returns me the error “Canvas is null” but i don’t understandwhy. I guess that maybe it could be cause i’ve passed the variable id in a bad way.

<html>
<canvas id="c1">
Your browser doesn't support canvas!
</canvas>

<video style="display:none;" id="video1" controls height="600px" width="800px" >
<source src="videos/movie.mp4" type="vide/mp4" >
<source src="videos/movie.ogv" type='video/ogg; codecs="theora, vorbis"'/>
<source src="videos/movie.webm" type='video/webm' >
</video>


<script type="text/javascript">

document.addEventListener('DOMContentLoaded', function () {

    video = document.getElementById("video1");
    video.height = 600;
    video.width = 400;
    video.play();
    aggiornacanvas("c1");

    function aggiornacanvas(id) {
        canvas = document.getElementById(id);
        canvasContext = canvas.getContext("2d");
        canvasContext.drawImage(video, 0, 0);
        data = canvasContext.getImageData(0, 0, canvas.width, canvas.height);

        //Modificare qui i dati dell'immagine
        canvasContext.putImageData(data, 0, 0);
        setTimeout(aggiornacanvas, 0);

    }




}, false);    


</script>
</html>

Ok, now it works but there is another errors

function aggiornacanvas(id)
{
    canvas = document.getElementById(id);
    canvasContext = canvas.getContext("2d");
    canvasContext.drawImage(video,0,0);
    var data = canvasContext.getImageData(0,0,canvas.width,canvas.height);
    alert("ok");    
    canvasContext.putImageData(data,0,0);
    setTimeout(aggiornacanvas(id),40);

}   

In this way it not works, and i get ok only one time…but if i write

function aggiornacanvas(id)
{
    canvas = document.getElementById(id);
    canvasContext = canvas.getContext("2d");
    canvasContext.drawImage(video,0,0);
    //var data = canvasContext.getImageData(0,0,canvas.width,canvas.height);
    alert("ok");    
    //canvasContext.putImageData(data,0,0);
    setTimeout(aggiornacanvas(id),40);

}   

it works!The problem is that i think that lines are correnct so i can’t understand why it doesn’t work whit them 🙁

UPDATED It works!That was a problem of browser that don’t allow to access at imagedata locally! THANKS guys, my first question on there it’s been answered!

  • 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-05-28T05:39:44+00:00Added an answer on May 28, 2026 at 5:39 am

    You are calling aggiornacanvas from your setTimeout, but aggiornacanvas requires a parameter – the id of your canvas element. Since that parameter is missing, your variable canvas is null. Hence, the error.

    Change your setTimeout to call aggiornacanvas with a parameter by wrapping it in an anonymous function.

    setTimeout(function () {
        aggiornacanvas(id);
    }, 0);
    

    But, holy smokes! Don’t do that! This will call aggiornacanvas over and over without stopping and spike your CPU! What are you trying to achieve?

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

Sidebar

Related Questions

I was just looking at this code and i don't understand what RETURN TRUE
I just started working in a .Net company and I saw this code but
I keep getting uncaught handler error in this code and I don't know why.
Why this code don't work,when i want run this code vwd 2008 express show
can anyone tell me why this code don't work: $q = $_GET['q']; // Load
I'm reading this code sample : And since I don't know C#, I decided
I don't understand the rationale of this code, taken from javax.swing.event.EventListenerList docs: protected void
I have this code to draw an ellipse in the screen but I don't
Checkstyle reports this code as The double-checked locking idiom is broken, but I don't
I have this code, I know I'm missing something but don't know what. It

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.