The author ( SiDChik@mail.ru ) does not have an account so he persuaded me to post this article
Recently, I got a job as a WEB-Developer, making an on-line map. In addition to the banal movement, I have to draw various objects on the map, for which I use
Canvas . If you search on Habré, you can find a couple of topics about this technology. In short, this is a tool for drawing graphics using JavaScript.
By default, this tool is not supported in IE, for this you can search and find the
ExCanvas script. To install it, just connect a single javascript file.
In the course of the work, a situation arose that requires the dynamic creation of a canvas. Unfortunately, something like
document.createElement ('canvas'); refused to work in IE. And when calling the getContent function, an error occurred. At the same time, at the output I should get a “popular” product, therefore, cross-browser is necessary.
Googling found another version of the script, added by one kind programmer who promised that the error was fixed (
NewExcanvas ). The option described in the topic was not fully working. Paradoxically, but the fact - refused to work in Google Chrome! In the end, a simple function was written:
')
//// (, )
function createCanvas(w,h)
{
var canvas = excanvas( document .createElement( "canvas" ));
if (canvas===undefined)
{
var canvas = document .createElement( "canvas" );
}
canvas.width=w;
canvas.height=h;
canvas.style.width=w+ 'px' ;
canvas.style.height=h+ 'px' ;
return canvas
}
* This source code was highlighted with Source Code Highlighter .
From the code it is clear that to create a canvas, it is necessary to specify the width, height of the object. At the same time, these dimensions need to be specified both through the style and by changing the value of the corresponding attributes.
It should be noted that this technology works under nix browsers, and does not require installation of additional plug-ins. Therefore, if you rewrite kazualki for this tool, you can count on the mass of the project, again because of cross-browser, and small requirements.