Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript canvas not working
    primarykey
    data
    text
    <p>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.</p> <p>This is my index file</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Lab1&lt;/title&gt; &lt;script type="text/javascript" src="javascript/canvas.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;canvas id="canvas" width="800" height="600"&gt; Your browser does not support the canvas tag &lt;/canvas&gt; &lt;p&gt;This is a simple 'Hello World' lab tutorial using the HTML5 canvas.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And this is my javascript file</p> <pre><code>// 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(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload