Problem with add dynamically elements canvas

58 views
Skip to first unread message

Jose A

unread,
Apr 24, 2008, 12:13:49 PM4/24/08
to google-excanvas
Hi!!
I'm triying to add dynamically new elements canvas to my web, by
appendChild method, with G_vmlCanvasManager.initElement() I have got
that it works in ie, but when I resize the window of navigator, an
exception appears in resize method in exCanvas.js

Somebody knows some solution to this problem ??

Thanks

Emil A Eklund

unread,
Apr 24, 2008, 1:13:40 PM4/24/08
to google-...@googlegroups.com
On Thu, 2008-04-24 at 09:13 -0700, Jose A wrote:
> Hi!!
> I'm triying to add dynamically new elements canvas to my web, by
> appendChild method, with G_vmlCanvasManager.initElement() I have got
> that it works in ie, but when I resize the window of navigator, an
> exception appears in resize method in exCanvas.js

Hi,

I haven't seen that type of error before. What does the error message
say?

Also, if you could post a copy of the HTML file triggering the problem
that would be great.

--
Emil A Eklund
e...@eae.net

signature.asc

Jose A

unread,
Apr 25, 2008, 3:55:39 AM4/25/08
to google-excanvas
Hi!
The problem is when you resize the window of the Web Browser (in
Explorer 7). The first time all works perfectly but when you resize
the window you can´t paint again the draw. The code is:

//mapa is a div object

//Creation of a div that will contain the canvas tag
var nombre="dibujoCanvas"
var html ="<div id='"+nombre+"' style='position:absolute;left:
0px;top:0px;width:"+mapa.GetAncho()+";height:"+mapa.GetAlto()
+";overflow:hidden; display:block;'>";
mapa.DivGraficos.innerHTML+=html;

//get the new div
var divCanvas = document.getElementById("dibujoCanvas");

var canvas = document.createElement("canvas");
canvas.setAttribute("id","canvas");
divCanvas.appendChild(canvas);

if(BrowserDetect.browser == "Explorer"){
canvas=window.G_vmlCanvasManager.initElement(canvas);
}
draw(); //Function that draw a triangle

It draws in explorer but, when I resize the explorer window a
exception appears in the resize function of excanvas.js, the error is
"e.srcElement" reference null:
function onResize(e) {
var el = e.srcElement;
if (el.firstChild) {
el.firstChild.style.width = el.clientWidth + 'px';
el.firstChild.style.height = el.clientHeight + 'px';
}
}

Thanks!!!!


Greg Houston

unread,
Apr 25, 2008, 1:02:54 PM4/25/08
to google-...@googlegroups.com
Jose,

I don't know if it will solve your issue or not, but right after
setting the ID attribute, you might try setting the width and height
attributes of your canvas as well.

- Greg

Erik Arvidsson

unread,
Apr 25, 2008, 3:22:04 PM4/25/08
to google-...@googlegroups.com
innerHTML += is dangerous since it removes the existing DOM. Could it
be that you have actually removed the canvas element?

--
erik

Reply all
Reply to author
Forward
0 new messages