Prototype itself throws errors in IE7

171 views
Skip to first unread message

Luke

unread,
Aug 26, 2011, 11:51:06 AM8/26/11
to prototype-s...@googlegroups.com
Hi

I'm trying to get a project I'm working on IE7-proof and I'm running into errors right from the start. The project is almost finished so I'm already including a lot of scripts and already have a lot of markup. When I load my page I get the error


Object doesn't support this property or method. prototype.js line 291 character 7


...and lot's of others, but this one occurs in prototype.js pretty much is the basis for everything else. All scripts depend on one call in a "dom:loaded"-observer to be exectuted. I commented that line out so nothing get's executed but I still get the error in prototype.js. And I have no idea where to start. Fermion in the IRC-channel told my prototype doesn't work in quirksmode in IE7. I'm using XHTML 1.0 Transitional and I get validation-errors because I use custom attributes in some tags. But I created a file that uses Prototype and has custom attributes for testing pruposes and that page works well.

If someone has an idea or a tip it's very appreciated.

Thanks and have a nice weekend,
Lukas

Walter Lee Davis

unread,
Aug 26, 2011, 12:30:26 PM8/26/11
to prototype-s...@googlegroups.com
This particular error will crop up on IE if you have not explicitly
"extended" the object you're calling a Prototype method on. If you use
the normal Prototype "finder" methods, then any element returned will
always be extended (have all of the Prototype methods added into it).
And on normal browsers, once you extend one element, you've extended
all of them, because of how prototype (little p) works in JavaScript.
But IE doesn't follow those rules explicitly, so each element has to
be extended before it can be operated on.

Rough example:

[1,2,3].each(function(n){ $('someDiv').insert(n + 2); });

will output 345 in your DIV in any browser other than IE.

$A([1,2,3]).each ... etc.

will do it everywhere.

Walter

> --
> You received this message because you are subscribed to the Google
> Groups "Prototype & script.aculo.us" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/prototype-scriptaculous/-/dxQftnqYLjoJ
> .
> To post to this group, send email to prototype-s...@googlegroups.com
> .
> To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en
> .

T.J. Crowder

unread,
Aug 27, 2011, 4:54:08 AM8/27/11
to Prototype & script.aculo.us
Hi,

On Aug 26, 5:30 pm, Walter Lee Davis <wa...@wdstudio.com> wrote:
> Rough example:
>
> [1,2,3].each(function(n){ $('someDiv').insert(n + 2); });
>
> will output 345 in your DIV in any browser other than IE.
>
> $A([1,2,3]).each ... etc.
>
> will do it everywhere.

Actually, no. The extensions to arrays, functions, and strings are all
automatic (at the Array.prototype, etc., level) even on IE. It's only
DOM elements that can't be extended prototypically on IE and so have
to be passed through `$` (or Element.extend`) before you use
Prototype's extensions to them.

So this would add a class name on any browser other than IE:

var p = document.createElement('p');
p.addClassName("foo");

...but on IE that would cause the error Lukas is seeing. You have to
do this:

var p = $(document.createElement('p'));
p.addClassName("foo");

...to be compatible with IE (see also below). Prototype has to extend
each element individually, because IE doesn't allow you to extend the
prototype of DOM elements like other browsers do.

Lukas, all element instances you retrieve or create via Prototype
methods will automatically be extended for you, so for instance this
works without an explicit `$`:

var p = new Element('p');
p.addClassName("foo");

...because Prototype's `Element` constructor makes sure the element is
extended before it gives it back to you. It's only when you've gotten
an element reference directly from the DOM that you have to make sure
to pass it through `$`. Note that passing an element through `$` more
than once is a harmless no-op.

Details:
http://www.prototypejs.org/learn/extensions

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

Luke

unread,
Aug 29, 2011, 3:37:52 AM8/29/11
to prototype-s...@googlegroups.com
Ok, thank you guys but the problem was something different. It's almost emberassing ^^. I simply included prototype.js twice. While every normal Browser doesn't care, IE7 throws the above mentioned errors. Thanks though for your responses and sorry for having wasted your time ;)

Lukas

Shane McCarron

unread,
Aug 29, 2011, 9:50:31 AM8/29/11
to prototype-s...@googlegroups.com
FYI so does IE6.  IE8 doesn't seem to mind.

On Mon, Aug 29, 2011 at 2:37 AM, Luke <kickin...@gmail.com> wrote:
Ok, thank you guys but the problem was something different. It's almost emberassing ^^. I simply included prototype.js twice. While every normal Browser doesn't care, IE7 throws the above mentioned errors. Thanks though for your responses and sorry for having wasted your time ;)

Lukas

--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.

To post to this group, send email to prototype-s...@googlegroups.com.
To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.



--
Shane McCarron
halin...@gmail.com
Reply all
Reply to author
Forward
0 new messages