Method of dom/HTMLCanvasElementdom/HTMLCanvasElement
Syntaxvar object = object.getContext();
Parameters contextId
The identifier (ID) of the type of canvas to create.
Return ValueReturns an object of type DOM NodeDOM Node
ICanvasRenderingContext2D
The context object.
ExamplesThe following code example uses getContext to get a context to use to show a filled rectangle and filled text.
<!DOCTYPE html>
<head>
<script type="text/javascript">
function draw()
{
var canvas = document.getElementById("MyCanvas");
if (canvas.getContext)
{
var ctx = canvas.getContext("2d");
ctx.font = "italic 36px/2 Unknown Font, sans-serif";
ctx.fillStyle = "blue";
ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.fillStyle = "white";
ctx.fillText ("Hello World",canvas.width/2,canvas.height*.8);
}
}
</script>
</head>
<body onload="draw()" bgcolor="lightgray" >
<div>
<canvas id="MyCanvas" width="500" height="500" > </canvas>
</div>
</body>
</html>
Notes Remarks
The getContext method returns null if the contextId value is not supported.
Syntax Standards informationMicrosoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4