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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:10:34+00:00 2026-06-15T11:10:34+00:00

I am trying to create a javascript canvas using an external javascript file. but

  • 0

I am trying to create a javascript canvas using an external javascript file. but for some reason when I run my code instead of getting the canvas I have coded I just get a white block. The chrome debugger finds no problem with my code so I am lost any help would be greatly appriciated.

This is my index file

<!doctype html>
    <html>
        <head>
            <title>Lab1</title> <script type="text/javascript" src="javascript/canvas.js"></script>
        </head>
        <body>
            <canvas id="canvas" width="800" height="600">
                Your browser does not support the canvas tag
            </canvas>
            <p>This is a simple 'Hello World' lab tutorial using the HTML5 canvas.</p>
        </body>
    </html>

And this is my javascript file

// check to see if the browser supports 
// the addEventListener function 
if(window.addEventListener) 
{
window.addEventListener 
( 
'Load', // this is the load event 
onLoad, // this is the event handler we are going to write 
false // useCapture boolean value 
);
}

// the window load event handler 
function onLoad() 
{ 
var canvas; 
var context;

// this function will initialise our variables 
function initialise() 
{
    // Find the canvas element using its id attribute. 
    canvas = document.getElementById('canvas'); 
    // if it couldn't be found 
    if (!canvas) 
    { 
        // make a message box pop up with the error. 
        alert('Error: I cannot find the canvas element!'); 
        return; 
    }
    // check if there is a getContext function 
    if (!canvas.getContext) 
    { 
        // make a message box pop up with the error. 
        alert('Error: no canvas.getContext!'); 
        return; 
    }
    // Get the 2D canvas context. 
    context = canvas.getContext('2d'); 
    if (!context) 
    { 
        alert('Error: failed to getContext!'); 
        return; 
    }
}

    // this function will actually draw on the canvas 
    function draw() 
    { 
        // set the draw fill style colour to black 
        context.fillStyle = "#000000"; 
        // fill the canvas with black 
        context.fillRect(0,0,canvas.width,canvas.height); 
        // choose a font for our message 
        context.font = "40pt Calibri"; 
        // set the draw fill colour to white 
        context.fillStyle = "#ffffff"; 
        // draw the text at the specified position 
        context.fillText("Hello World!", 150, canvas.height); 
    }
// call the initialise and draw functions 
initialise(); 
draw(); 
}
  • 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-15T11:10:35+00:00Added an answer on June 15, 2026 at 11:10 am

    The event type needs to be written lowercase: load, i.e.

    window.addEventListener('load', onLoad, false);
    

    A list of available event types is referenced for example by Mozilla.

    Just a hint: You can set a breakpoint in your onLoad function with your Chrome debugger to make sure that it is called by your event listener. It was not and that drew my attention to your addEventListener method call.

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

Sidebar

Related Questions

I'm trying to create an animation using HTML5 canvas and Javascript. I have very
I am trying to create a dynamic bar in HTML using javascript. I have
I'm trying to create some javascript code that will display a javascript form (from
I am trying to create a form using only JavaScript. I mean create a
I'm trying to create a public gist via javascript. I'm not using any authentication
I'm trying to create a Captcha in JavaScript but I ran into issues. I
I'm trying to create a simple extensible class in javascript but when setting property
I am trying to create a new Element in my javascript code and append
i am just trying to create a link which execute some JavaScript in stead
I'm trying to create a thumbnail image on the client side using javascript and

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.