Latest excanvas version doesn't allow dynamic canvas creation.

336 views
Skip to first unread message

roliveira

unread,
Sep 3, 2008, 1:20:02 PM9/3/08
to google-excanvas, er...@eae.net
I'm using DynamicInitializationCanvas.zip (as said in post «canvas
resize problem in IE») and it creates an error on FF:
«
Node cannot be inserted at the specified point in the hierarchy" code:
"3
»

Erik Arvidsson sugested the use of the latest files from
http://excanvas.svn.sourceforge.net/viewvc/excanvas/

I've tried it but it doesn't seem to allow creating <canvas> elements
with createElement.

Does anyone know how to solve this?

Ruben.

roliveira

unread,
Sep 4, 2008, 10:57:31 AM9/4/08
to google-excanvas
First part is solved.

Second part is still problem:

Erik Arvidsson sugested the use of the latest files from
http://excanvas.svn.sourceforge.net/viewvc/excanvas/

I've tried it but it doesn't seem to allow creating <canvas> elements
with createElement.

Does anyone know how to solve this?

On Sep 3, 6:20 pm, roliveira <mail.rolive...@gmail.com> wrote:
> I'm using DynamicInitializationCanvas.zip (as said in post «canvas
> resize problem in IE») and it creates an error on FF:
> «
> Node cannot be inserted at the specified point in the hierarchy" code:
> "3
> »
>
> Erik Arvidsson sugested the use of the latest files fromhttp://excanvas.svn.sourceforge.net/viewvc/excanvas/

Emil A Eklund

unread,
Sep 4, 2008, 12:42:03 PM9/4/08
to google-...@googlegroups.com
On Thu, 2008-09-04 at 07:57 -0700, roliveira wrote:
> First part is solved.
>
> Second part is still problem:
>
> Erik Arvidsson sugested the use of the latest files from
> http://excanvas.svn.sourceforge.net/viewvc/excanvas/
>
> I've tried it but it doesn't seem to allow creating <canvas> elements
> with createElement.
>
> Does anyone know how to solve this?

You'll have to create your own wrapper around createElement that
initializes the canvas element for you. From the name of the patches
version you where using before I assume that's what it does.

Copy the createElement wrapper from that version
(DynamicInitializationCanvas.zip) into your script and you should be all
set.

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

signature.asc

roliveira

unread,
Sep 5, 2008, 4:55:03 AM9/5/08
to google-excanvas
Emil,

I allready did that although i admit i didn't spend much time on it.
The script i'm using is working so for now the need for a new one is
relative. But i'd like to use the latest file so I'll give it a try
gain.

Thank you Emil!
>  signature.asc
> < 1KViewDownload

Ole Laursen

unread,
Sep 10, 2008, 3:34:41 PM9/10/08
to google-excanvas
On Sep 5, 10:55 am, roliveira <mail.rolive...@gmail.com> wrote:
> I allready did that although i admit i didn't spend much time on it.
> The script i'm using is working so for now the need for a new one is
> relative. But i'd like to use the latest file so I'll give it a try
> gain.

I tried the SVN release just now, and I'm running into a problem too.
As far as I can tell, the problem is in

function CanvasRenderingContext2D_(surfaceElement)

where my IE 6 just stops executing the function when it reaches the
line

surfaceElement.appendChild(el);

I put in an alert before this line, alert comes out, put in an alert
after, no alert. So getContext returns undefined, so obviously nothing
is then working.

My code is like this

if ($.browser.msie)
canvas = window.G_vmlCanvasManager.initElement(canvas);
ctx = canvas.getContext("2d");
// ctx is undefined

It works perfectly with the released excanvas 0.2. I had a look, and
the most obvious candidate is the changes in revision 27:

"Use the document.createElement('canvas') hack that was exposed by
Sjoerd
Visscher last week. This allows us to remove fixElement_
completely."

http://excanvas.svn.sourceforge.net/viewvc/excanvas/excanvas.js?r1=27&r2=26&pathrev=27

Maybe it isn't working in IE 6?

I was hoping to get hold of a new release with leak fixes for the next
release of Flot (plotting library for jQuery).

Ole

Ole Laursen

unread,
Oct 14, 2008, 12:03:35 PM10/14/08
to google-excanvas
On Sep 10, 9:34 pm, Ole Laursen <o...@iola.dk> wrote:
>  http://excanvas.svn.sourceforge.net/viewvc/excanvas/excanvas.js?r1=27...
>
> Maybe it isn't working in IE 6?

Has anyone here successfully run the SVN version of excanvas on IE 6
with dynamically inserted canvases?

Ole

Erik Arvidsson

unread,
Oct 14, 2008, 12:38:00 PM10/14/08
to google-excanvas
I can take a look at this at work where I got access to IE6.

2008/10/14 Ole Laursen <ol...@iola.dk>:
--
erik

Maciek

unread,
Nov 20, 2008, 11:21:13 AM11/20/08
to google-excanvas
Inspecting this breakpoint in the debugger reveals that
surfaceElement.canHaveChildren is false, so it looks like IE doesn't
think this is a totally valid element.

Has anyone made any progress on this?

On Oct 14, 11:38 am, "Erik Arvidsson" <erik.arvids...@gmail.com>
wrote:
> I can take a look at this at work where I got access to IE6.
>
> 2008/10/14 Ole Laursen <o...@iola.dk>:

jarredh

unread,
Nov 25, 2008, 8:40:41 PM11/25/08
to google-excanvas

On Nov 21, 2:21 am, Maciek <maciekadw...@gmail.com> wrote:
> Inspecting this breakpoint in the debugger reveals that
> surfaceElement.canHaveChildren is false, so it looks like IE doesn't
> think this is a totally valid element.
>
> Has anyone made any progress on this?
>

I noticed the same problem.
It fails when creating the canvas using (jquery) $('<canvas
width="400" height="200"></canvas>').
But works fine when created using $(document.createElement
('canvas')).width(400).height(200).
From what I can tell the difference is the first method uses innerHTML
to create the canvas element.

-Jarred

Erik Arvidsson

unread,
Nov 26, 2008, 12:35:25 AM11/26/08
to google-excanvas
You need to call initElement on the element. See earlier discussions
on this topic.

2008/11/25 jarredh <jarred...@gmail.com>:
--
erik

jarredh

unread,
Nov 27, 2008, 12:15:20 AM11/27/08
to google-excanvas
Sorry, I should have been more clear. I am calling initElement() on
the canvas after creating it.

This works fine:
window.G_vmlCanvasManager.initElement( $(document.createElement
('canvas')).appendTo(document.body).get(0) )

This fails:
window.G_vmlCanvasManager.initElement( $('<canvas/>').appendTo
(document.body).get(0) )

On Nov 26, 3:35 pm, "Erik Arvidsson" <erik.arvids...@gmail.com> wrote:
> You need to call initElement on the element.  See earlier discussions
> on this topic.
>
> 2008/11/25 jarredh <jarred.hol...@gmail.com>:

lrbabe

unread,
Nov 27, 2008, 6:59:06 AM11/27/08
to google-excanvas
I have got the same problem here. Despite using initElement,
"surfaceElement.appendChild(el);" always throw an error.

Ryan Schmidt

unread,
Dec 23, 2008, 10:54:03 PM12/23/08
to google-...@googlegroups.com
On Nov 26, 2008, at 23:15, jarredh wrote:

> This works fine:
> window.G_vmlCanvasManager.initElement( $(document.createElement
> ('canvas')).appendTo(document.body).get(0) )
>
> This fails:
> window.G_vmlCanvasManager.initElement( $('<canvas/>').appendTo
> (document.body).get(0) )

I'm noticing similar weirdness using the Prototype library and its
element creation syntactic sugar.


This works:

canvas = document.createElement('canvas');
canvas.id = 'my_canvas';
if (Prototype.Browser.IE) {
G_vmlCanvasManager.initElement(canvas);
canvas = $(canvas.id);
}


This fails:

canvas = new Element('canvas');
canvas.id = 'my_canvas';
if (Prototype.Browser.IE) {
G_vmlCanvasManager.initElement(canvas);
canvas = $(canvas.id);
}


kangax

unread,
Dec 24, 2008, 12:13:59 AM12/24/08
to google-excanvas
On Dec 23, 10:54 pm, Ryan Schmidt <google-2...@ryandesign.com> wrote:
[...]
> This works:
>
>         canvas = document.createElement('canvas');
>         canvas.id = 'my_canvas';
>         if (Prototype.Browser.IE) {

It's a bad idea to use browser sniffing here. Instead, why not check
for a presence of `getContext` method on canvas element?

[...]

--
kangax

Ryan Schmidt

unread,
Dec 24, 2008, 12:42:55 AM12/24/08
to google-...@googlegroups.com
On Dec 23, 2008, at 23:13, kangax wrote:

> On Dec 23, 10:54 pm, Ryan Schmidt wrote:
>
>> if (Prototype.Browser.IE) {
>
> It's a bad idea to use browser sniffing here. Instead, why not check
> for a presence of `getContext` method on canvas element?

I too am a proponent of functionality testing instead of browser
sniffing, however is it guaranteed that every browser that is missing
the getContext method also supports VML? I think it's only IE that
has VML, hence the IE browser test. Not to mention that excanvas.js
is included in my page via IE conditional comments which only IE
understands, and of course that ExplorerCanvas is designed
specifically for Internet Explorer.

Anyway the point I was trying to make is that Prototype's "new Element
('canvas')" doesn't work (just like Jarred reported that jQuery's "$
('<canvas/>')" doesn't work) while the standard
"document.createElement('canvas')" does work.

Fabien

unread,
Dec 24, 2008, 4:39:41 AM12/24/08
to google-excanvas
That's weird but it works well for the latest version of Flotr with
prototype 1.6.0.2 using new Element. I think it works with ie 6 too.
Message has been deleted

Ole Laursen

unread,
Feb 20, 2009, 10:51:44 AM2/20/09
to google-excanvas
On 24 Dec. 2008, 06:42, Ryan Schmidt <google-2...@ryandesign.com>
wrote:
> Anyway the point I was trying to make is that Prototype's "new Element
> ('canvas')" doesn't work (just like Jarred reported that jQuery's "$
> ('<canvas/>')" doesn't work) while the standard  
> "document.createElement('canvas')" does work.

Same problem and same solution here with jQuery 1.2.6. Maybe the
changes in revision 27 I referred to earlier in this thread should be
taken out if they don't work with innerHTML?

Ole

--
Looking for edge? - http://www.yayart.com
Message has been deleted

Erik Arvidsson

unread,
Feb 22, 2009, 7:46:55 PM2/22/09
to alexandre...@gmail.com, google-excanvas
Hi Alexandre,

You will need to sign the CLA before I can look at the patch.

http://groups.google.com/group/google-excanvas/browse_thread/thread/df76efbca39093b1/88d0893a26b5bb0e?lnk=gst&q=cla#88d0893a26b5bb0e

Thanks,

erik

On Fri, Feb 20, 2009 at 15:30, Alkarex <alexandre...@gmail.com> wrote:
>
> Following Ole's idea, I have made a patch from rev 44 to revert
> changes of rev 27 and it seems to work fine (at least for my test
> cases) also during dynamic creation, in IE6, IE7, IE8 all modes
> (including IE8 64 bits).
> See http://code.google.com/p/flot/issues/detail?id=66#c8 for patch or
> full file.
>
> And a link of interest discussing a very related issue
> http://piecesofrakesh.blogspot.com/2007/02/ies-unknown-runtime-error-when-using.html
>
> Best regards,
> Alexandre
> http://alexandre.alapetite.fr
>
> --- /js/excanvas0.js Revision 44 (2009-01-02)
> +++ /js/excanvas1.js Revert changes of version 27
> @@ -125,6 +125,30 @@
> }
> },
>
> + fixElement_: function (el) {
> + // in IE before version 5.5 we would need to add HTML: to the
> tag name
> + // but we do not care about IE before version 6
> + var outerHTML = el.outerHTML;
> +
> + var newEl = el.ownerDocument.createElement(outerHTML);
> + // if the tag is still open IE has created the children as
> siblings and
> + // it has also created a tag with the name "/FOO"
> + if (outerHTML.slice(-2) != "/>") {
> + var tagName = "/" + el.tagName;
> + var ns;
> + // remove content
> + while ((ns = el.nextSibling) && ns.tagName != tagName) {
> + ns.removeNode();
> + }
> + // remove the incorrect closing tag
> + if (ns) {
> + ns.removeNode();
> + }
> + }
> + el.parentNode.replaceChild(newEl, el);
> + return newEl;
> + },
> +
> /**
> * Public initializes a canvas element so that it can be used as
> canvas
> * element from now on. This is called automatically before the
> page is
> @@ -135,7 +159,7 @@
> */
> initElement: function(el) {
> if (!el.getContext) {
> -
> + el = this.fixElement_(el);
> el.getContext = getContext;
>
> // Remove fallback content. There is no way to hide text
> nodes so we
>
Reply all
Reply to author
Forward
0 new messages