Wrote a piece of code for HTML5 's canvas, in Chrome, Canvas object [Object] has no method ' GetContext '
Cause analysis: Because JS before the page load, there is no canvas, so the page can be loaded to get canvas objects.
Start code:
<span style= "White-space:pre" > </span>var canvas = document.getElementById (' Gdcanvas ');
The var context = Canvas.getcontext (' 2d ');//Here Gets the contextual contexts Context.beginpath () of the processing API through canvas
;
Context.moveto (the);
Context.lineto (in);
Context.stroke ();
To modify the code:
<span style= "color: #ff0000;" >window.onload = function () {</span>
var canvas = document.getElementById (' Gdcanvas ');
The var context = Canvas.getcontext (' 2d ');//Here Gets the contextual contexts Context.beginpath () of the processing API through canvas
;
Context.moveto (the);
Context.lineto (in);
Context.stroke ();
<span style= "color: #ff0000;" >};</span>