Google Groups Home
Help | Sign in
getContext() not working...
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
sihyung@gmail.com  
View profile
 More options Mar 4, 12:51 pm
From: "sihy...@gmail.com" <sihy...@gmail.com>
Date: Tue, 4 Mar 2008 09:51:31 -0800 (PST)
Local: Tues, Mar 4 2008 12:51 pm
Subject: getContext() not working...
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.

Thanks,

Danny

<canvas id="stuff" height="150" width="150">some default</canvas>

<script type="text/javascript" src="newExcanvas.js" ></script>
<script type="text/javascript" >

var stuff= document.getElementById('stuff');
stuff.getContext('2d');

</script>


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
timothytoe  
View profile
 More options Mar 4, 1:31 pm
From: timothytoe <timothy...@gmail.com>
Date: Tue, 4 Mar 2008 10:31:34 -0800 (PST)
Local: Tues, Mar 4 2008 1:31 pm
Subject: Re: getContext() not working...
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:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sihyung@gmail.com  
View profile
 More options Mar 4, 2:13 pm
From: "sihy...@gmail.com" <sihy...@gmail.com>
Date: Tue, 4 Mar 2008 11:13:50 -0800 (PST)
Local: Tues, Mar 4 2008 2:13 pm
Subject: Re: getContext() not working...
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:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
timothytoe  
View profile
 More options Mar 4, 2:38 pm
From: timothytoe <timothy...@gmail.com>
Date: Tue, 4 Mar 2008 11:38:04 -0800 (PST)
Local: Tues, Mar 4 2008 2:38 pm
Subject: Re: getContext() not working...
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:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Arvidsson  
View profile
 More options Mar 4, 4:50 pm
From: "Erik Arvidsson" <erik.arvids...@gmail.com>
Date: Tue, 4 Mar 2008 13:50:16 -0800
Local: Tues, Mar 4 2008 4:50 pm
Subject: Re: getContext() not working...
The problem is that you need an instance of the element to add the
getContext method.

--
erik

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
timothytoe  
View profile
 More options Mar 4, 11:27 pm
From: timothytoe <timothy...@gmail.com>
Date: Tue, 4 Mar 2008 20:27:30 -0800 (PST)
Local: Tues, Mar 4 2008 11:27 pm
Subject: Re: getContext() not working...
Are you sure that can't be handled transparently in excanvas?

On Mar 4, 1:50 pm, "Erik Arvidsson" <erik.arvids...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Klaus Reimer  
View profile
 More options Mar 5, 3:05 am
From: Klaus Reimer <k...@ailis.de>
Date: Wed, 05 Mar 2008 09:05:52 +0100
Local: Wed, Mar 5 2008 3:05 am
Subject: Re: getContext() not working...

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)

  signature.asc
< 1K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
timothytoe  
View profile
 More options Mar 5, 10:22 am
From: timothytoe <timothy...@gmail.com>
Date: Wed, 5 Mar 2008 07:22:31 -0800 (PST)
Local: Wed, Mar 5 2008 10:22 am
Subject: Re: getContext() not working...
That's a great idea. Seems like it would be worth it, considering the
number of people who run into the problem.

On Mar 5, 12:05 am, Klaus Reimer <k...@ailis.de> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Clay  
View profile
 More options Mar 5, 12:17 pm
From: Steve Clay <st...@mrclay.org>
Date: Wed, 05 Mar 2008 12:17:27 -0500
Local: Wed, Mar 5 2008 12:17 pm
Subject: Re: getContext() not working...

Klaus Reimer wrote:
> origCreateElement = document.createElement;
> document.createElement = function(tagName) ...

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');};

[1] http://groups.google.com/group/google-excanvas/msg/46d9645009827294

--
Steve Clay
http://mrclay.org/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
timothytoe  
View profile
 More options Mar 5, 12:22 pm
From: timothytoe <timothy...@gmail.com>
Date: Wed, 5 Mar 2008 09:22:18 -0800 (PST)
Local: Wed, Mar 5 2008 12:22 pm
Subject: Re: getContext() not working...
I don't see how it can be ignored. Other than this problem, excanvas
does a pretty great job of working as a drop-in that you can ignore.

What is the license for excanvas? Can we fork this sucker off and
start improving it?

On Mar 5, 9:17 am, Steve Clay <st...@mrclay.org> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.