I am testing the waters with excanvas but whenever I call getContext,
ie7 throws an error saying that the method is not supported. Any
ideas? I have included my simple piece of code below.
This one cost me many hours last Thursday and Friday. My situation was
that everything worked fine if the canvas was part of the html file,
but if I created the canvas on-the-fly with JavaScript, I could not
get the context in IE.
I'm not sure why you're getting the problem, maybe because your check
comes so soon after the canvas is created.
Try one of these. The first is for jQuery. The second is if you don't
have jQuery.
if ($.browser.msie) { //if you're already being nasty all over
your code to handle IE nightmares, check for IE directly (example in
jQuery)
canvas=window.G_vmlCanvasManager.initElement(canvas);
}
if (typeof window.G_vmlCanvasManager!="undefined") { //a
friendlier way to check to see if we're in IE emulating Canvas
canvas=window.G_vmlCanvasManager.initElement(canvas);
}
I've checked both ways of doing it in FF, IE, Opera, and Safari on
Windows.
If it works, you owe me a beer. It's not my solution. I found it
checking into the charting library called "flot."
On Mar 4, 9:51 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote:
> I am testing the waters with excanvas but whenever I call getContext,
> ie7 throws an error saying that the method is not supported. Any
> ideas? I have included my simple piece of code below.
> This one cost me many hours last Thursday and Friday. My situation was
> that everything worked fine if the canvas was part of the html file,
> but if I created the canvas on-the-fly with JavaScript, I could not
> get the context in IE.
> I'm not sure why you're getting the problem, maybe because your check
> comes so soon after the canvas is created.
> Try one of these. The first is for jQuery. The second is if you don't
> have jQuery.
> if ($.browser.msie) { //if you're already being nasty all over
> your code to handle IE nightmares, check for IE directly (example in
> jQuery)
> canvas=window.G_vmlCanvasManager.initElement(canvas);
> }
> if (typeof window.G_vmlCanvasManager!="undefined") { //a
> friendlier way to check to see if we're in IE emulating Canvas
> canvas=window.G_vmlCanvasManager.initElement(canvas);
> }
> I've checked both ways of doing it in FF, IE, Opera, and Safari on
> Windows.
> If it works, you owe me a beer. It's not my solution. I found it
> checking into the charting library called "flot."
> On Mar 4, 9:51 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote:
> > Hi,
> > I am testing the waters with excanvas but whenever I call getContext,
> > ie7 throws an error saying that the method is not supported. Any
> > ideas? I have included my simple piece of code below.
Heh on the beer. I'm tempted to make you do it next time in in bay
area.
Searching the archives, this bug comes up over and over. My problem
was that it took me so long to nail down the problem line of code
because I just refused to believe that it was something like that.
I see that there's a sort-of-solution in the patch area to let you
create dynamic contexts, but it seems to me that overriding getContext
would be better so people don't have to even think about changing
their code.
I still feel like a newbie in JS, but shouldn't you be able to save
off the old getContext, intercept getContext calls, and then do that
IE hack?
I really shouldn't spend my time this way, but I'm going to try to fix
that booger for good.
On Mar 4, 11:13 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote:
> It works!!!! Hahaha. Looks like I owe you a beer, let me know if you
> are ever in the bay area.
> Thanks again,
> Danny
> On Mar 4, 10:31 am, timothytoe <timothy...@gmail.com> wrote:
> > This one cost me many hours last Thursday and Friday. My situation was
> > that everything worked fine if the canvas was part of the html file,
> > but if I created the canvas on-the-fly with JavaScript, I could not
> > get the context in IE.
> > I'm not sure why you're getting the problem, maybe because your check
> > comes so soon after the canvas is created.
> > Try one of these. The first is for jQuery. The second is if you don't
> > have jQuery.
> > if ($.browser.msie) { //if you're already being nasty all over
> > your code to handle IE nightmares, check for IE directly (example in
> > jQuery)
> > canvas=window.G_vmlCanvasManager.initElement(canvas);
> > }
> > if (typeof window.G_vmlCanvasManager!="undefined") { //a
> > friendlier way to check to see if we're in IE emulating Canvas
> > canvas=window.G_vmlCanvasManager.initElement(canvas);
> > }
> > I've checked both ways of doing it in FF, IE, Opera, and Safari on
> > Windows.
> > If it works, you owe me a beer. It's not my solution. I found it
> > checking into the charting library called "flot."
> > On Mar 4, 9:51 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote:
> > > Hi,
> > > I am testing the waters with excanvas but whenever I call getContext,
> > > ie7 throws an error saying that the method is not supported. Any
> > > ideas? I have included my simple piece of code below.
On Tue, Mar 4, 2008 at 11:38, timothytoe <timothy...@gmail.com> wrote:
> Heh on the beer. I'm tempted to make you do it next time in in bay > area.
> Searching the archives, this bug comes up over and over. My problem > was that it took me so long to nail down the problem line of code > because I just refused to believe that it was something like that.
> I see that there's a sort-of-solution in the patch area to let you > create dynamic contexts, but it seems to me that overriding getContext > would be better so people don't have to even think about changing > their code.
> I still feel like a newbie in JS, but shouldn't you be able to save > off the old getContext, intercept getContext calls, and then do that > IE hack?
> I really shouldn't spend my time this way, but I'm going to try to fix > that booger for good.
> On Mar 4, 11:13 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote: > > It works!!!! Hahaha. Looks like I owe you a beer, let me know if you > > are ever in the bay area.
> > Thanks again,
> > Danny
> > On Mar 4, 10:31 am, timothytoe <timothy...@gmail.com> wrote:
> > > This one cost me many hours last Thursday and Friday. My situation was > > > that everything worked fine if the canvas was part of the html file, > > > but if I created the canvas on-the-fly with JavaScript, I could not > > > get the context in IE.
> > > I'm not sure why you're getting the problem, maybe because your check > > > comes so soon after the canvas is created.
> > > Try one of these. The first is for jQuery. The second is if you don't > > > have jQuery.
> > > if ($.browser.msie) { //if you're already being nasty all over > > > your code to handle IE nightmares, check for IE directly (example in > > > jQuery) > > > canvas=window.G_vmlCanvasManager.initElement(canvas); > > > }
> > > if (typeof window.G_vmlCanvasManager!="undefined") { //a > > > friendlier way to check to see if we're in IE emulating Canvas > > > canvas=window.G_vmlCanvasManager.initElement(canvas); > > > }
> > > I've checked both ways of doing it in FF, IE, Opera, and Safari on > > > Windows.
> > > If it works, you owe me a beer. It's not my solution. I found it > > > checking into the charting library called "flot."
> > > On Mar 4, 9:51 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote:
> > > > Hi,
> > > > I am testing the waters with excanvas but whenever I call getContext, > > > > ie7 throws an error saying that the method is not supported. Any > > > > ideas? I have included my simple piece of code below.
> The problem is that you need an instance of the element to add the
> getContext method.
> On Tue, Mar 4, 2008 at 11:38, timothytoe <timothy...@gmail.com> wrote:
> > Heh on the beer. I'm tempted to make you do it next time in in bay
> > area.
> > Searching the archives, this bug comes up over and over. My problem
> > was that it took me so long to nail down the problem line of code
> > because I just refused to believe that it was something like that.
> > I see that there's a sort-of-solution in the patch area to let you
> > create dynamic contexts, but it seems to me that overriding getContext
> > would be better so people don't have to even think about changing
> > their code.
> > I still feel like a newbie in JS, but shouldn't you be able to save
> > off the old getContext, intercept getContext calls, and then do that
> > IE hack?
> > I really shouldn't spend my time this way, but I'm going to try to fix
> > that booger for good.
> > On Mar 4, 11:13 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote:
> > > It works!!!! Hahaha. Looks like I owe you a beer, let me know if you
> > > are ever in the bay area.
> > > Thanks again,
> > > Danny
> > > On Mar 4, 10:31 am, timothytoe <timothy...@gmail.com> wrote:
> > > > This one cost me many hours last Thursday and Friday. My situation was
> > > > that everything worked fine if the canvas was part of the html file,
> > > > but if I created the canvas on-the-fly with JavaScript, I could not
> > > > get the context in IE.
> > > > I'm not sure why you're getting the problem, maybe because your check
> > > > comes so soon after the canvas is created.
> > > > Try one of these. The first is for jQuery. The second is if you don't
> > > > have jQuery.
> > > > if ($.browser.msie) { //if you're already being nasty all over
> > > > your code to handle IE nightmares, check for IE directly (example in
> > > > jQuery)
> > > > canvas=window.G_vmlCanvasManager.initElement(canvas);
> > > > }
> > > > if (typeof window.G_vmlCanvasManager!="undefined") { //a
> > > > friendlier way to check to see if we're in IE emulating Canvas
> > > > canvas=window.G_vmlCanvasManager.initElement(canvas);
> > > > }
> > > > I've checked both ways of doing it in FF, IE, Opera, and Safari on
> > > > Windows.
> > > > If it works, you owe me a beer. It's not my solution. I found it
> > > > checking into the charting library called "flot."
> > > > On Mar 4, 9:51 am, "sihy...@gmail.com" <sihy...@gmail.com> wrote:
> > > > > Hi,
> > > > > I am testing the waters with excanvas but whenever I call getContext,
> > > > > ie7 throws an error saying that the method is not supported. Any
> > > > > ideas? I have included my simple piece of code below.
timothytoe wrote: > Are you sure that can't be handled transparently in excanvas?
It could be changed to handle it transparently. I did this before in my own humble attempt to build a Canvas/VML-Wrapper. It's possible to overwrite the document.createElement Method. This custom Method can then check if a "<canvas />" is going to be created. If not, then the original createElement method is called. If yes, then the special excanvas stuff can be called.
In this way it's handled transparently and all you have to do is conditionally including the excanvas.js in your page.
I think I did it like this (Don't have the code anymore):
origCreateElement = document.createElement; document.createElement = function(tagName) { var element = origCreateElement(tagName); if (tagName == "canvas" || tagName.toLowerCase().indexOf("<canvas") === 0) { ...Do excanvas initialization on element... } return element;
}
-- Bye, K <http://www.ailis.de/~k/> [A735 47EC D87B 1F15 C1E9 53D3 AA03 6173 A723 E391] (Finger k...@ailis.de to get public key)
> timothytoe wrote:
> > Are you sure that can't be handled transparently in excanvas?
> It could be changed to handle it transparently. I did this before in my
> own humble attempt to build a Canvas/VML-Wrapper. It's possible to
> overwrite the document.createElement Method. This custom Method can then
> check if a "<canvas />" is going to be created. If not, then the
> original createElement method is called. If yes, then the special
> excanvas stuff can be called.
> In this way it's handled transparently and all you have to do is
> conditionally including the excanvas.js in your page.
> I think I did it like this (Don't have the code anymore):
> origCreateElement = document.createElement;
> document.createElement = function(tagName)
> {
> var element = origCreateElement(tagName);
> if (tagName == "canvas" || tagName.toLowerCase().indexOf("<canvas")
> === 0)
> {
> ...Do excanvas initialization on element...
> }
> return element;
> }
> --
> Bye, K <http://www.ailis.de/~k/>
> [A735 47EC D87B 1F15 C1E9 53D3 AA03 6173 A723 E391]
> (Finger k...@ailis.de to get public key)
This makes at least four people who've suggested wrapping createElement over the last 2 years including myself [1]. The admins don't seem to be into the idea, but this continues to confound new users who're using new canvas elements because there's no docs/example for it. FWIW, here's the shortest code I can come up with:
var cv = document.createElement('canvas'); window.G_vmlCanvasManager && (cv = );
or faster if you plan to generate several:
var createCanvas = window.G_vmlCanvasManager ? function () { return G_vmlCanvasManager.initElement( document.createElement('canvas')); } : function () {return document.createElement('canvas');};
> This makes at least four people who've suggested wrapping createElement
> over the last 2 years including myself [1]. The admins don't seem to be
> into the idea, but this continues to confound new users who're using new
> canvas elements because there's no docs/example for it. FWIW, here's the
> shortest code I can come up with: