BillyRayPreachersSon
2008-May-28 14:11 UTC
Multiple copies of Prototype.js cause errors in IE6 & IE7
We''ve found that having multile copies of the Prototype.js file on a single page will cause IE6 and IE7 to throw JS errors - most notably when using methods on elements that have been extended. For example, take this quick test harness: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> window.onload = function() { alert( $(''wibble'').getElementsByClassName ); } </script> </head> <body> <div id="wibble"> <p>Some text...</p> </div> </body> </html> It works fine in Opera 9.26, Safari 3.1.1, IE 6, IE 7, and Fx 2.0.0.14. If you duplicate the script include line for Protoype so that 2 copies of the file are loaded, then you see "undefined" in IE6 and IE7, while all other browsers behave as I would expect. Unfortunately, this is an issue for us as we''re using a 3rd-party widget on our page which delivers v1.6.0.2 of Prototype after our page delivers the same version, and we have no control over what is loaded from the remote servers. Is there any way that Prototype can be modifed to detect itself, and gracefully do nothing if it''s already on the page? Alternatively, given we''re using the same version of Prototype as our widget, is there any way of somehow "disabling" theirs before it is loaded (so that when it is loaded, it does nothing, falling back on our version)? Thanks! Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Michael
2008-May-28 18:40 UTC
Re: Multiple copies of Prototype.js cause errors in IE6 & IE7
Why dont you just not include it in your page. Just use their copy if possible. Have you tried this in IE8 beta? Michael On May 28, 8:11 am, BillyRayPreachersSon <BillyRayPreachers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> We''ve found that having multile copies of the Prototype.js file on a > single page will cause IE6 and IE7 to throw JS errors - most notably > when using methods on elements that have been extended. For example, > take this quick test harness: > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> > <html> > <head> > <script type="text/javascript" src="prototype.js"></script> > > <script type="text/javascript"> > window.onload = function() { > alert( $(''wibble'').getElementsByClassName ); > } > </script> > </head> > > <body> > <div id="wibble"> > <p>Some text...</p> > </div> > </body> > </html> > > It works fine in Opera 9.26, Safari 3.1.1, IE 6, IE 7, and Fx > 2.0.0.14. If you duplicate the script include line for Protoype so > that 2 copies of the file are loaded, then you see "undefined" in IE6 > and IE7, while all other browsers behave as I would expect. > > Unfortunately, this is an issue for us as we''re using a 3rd-party > widget on our page which delivers v1.6.0.2 of Prototype after our page > delivers the same version, and we have no control over what is loaded > from the remote servers. > > Is there any way that Prototype can be modifed to detect itself, and > gracefully do nothing if it''s already on the page? > > Alternatively, given we''re using the same version of Prototype as our > widget, is there any way of somehow "disabling" theirs before it is > loaded (so that when it is loaded, it does nothing, falling back on > our version)? > > Thanks! > > Dan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
kangax
2008-May-28 20:51 UTC
Re: Multiple copies of Prototype.js cause errors in IE6 & IE7
Dan, Are there any errors thrown, or does it just stop working? - kangax On May 28, 10:11 am, BillyRayPreachersSon <BillyRayPreachers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> We''ve found that having multile copies of the Prototype.js file on a > single page will cause IE6 and IE7 to throw JS errors - most notably > when using methods on elements that have been extended. For example, > take this quick test harness: > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> > <html> > <head> > <script type="text/javascript" src="prototype.js"></script> > > <script type="text/javascript"> > window.onload = function() { > alert( $(''wibble'').getElementsByClassName ); > } > </script> > </head> > > <body> > <div id="wibble"> > <p>Some text...</p> > </div> > </body> > </html> > > It works fine in Opera 9.26, Safari 3.1.1, IE 6, IE 7, and Fx > 2.0.0.14. If you duplicate the script include line for Protoype so > that 2 copies of the file are loaded, then you see "undefined" in IE6 > and IE7, while all other browsers behave as I would expect. > > Unfortunately, this is an issue for us as we''re using a 3rd-party > widget on our page which delivers v1.6.0.2 of Prototype after our page > delivers the same version, and we have no control over what is loaded > from the remote servers. > > Is there any way that Prototype can be modifed to detect itself, and > gracefully do nothing if it''s already on the page? > > Alternatively, given we''re using the same version of Prototype as our > widget, is there any way of somehow "disabling" theirs before it is > loaded (so that when it is loaded, it does nothing, falling back on > our version)? > > Thanks! > > Dan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
BillyRayPreachersSon
2008-May-29 09:24 UTC
Re: Multiple copies of Prototype.js cause errors in IE6 & IE7
Michael, We cannot rely on their copy because our page has a need for Prototype before their widget is even invoked. Kangax, The error is simply "Object doesn''t support this property or method" when trying to call the "getElementsByClassName" method on an element. Now, I know that "getElementsByClassName" has been deprecated, but this isn''t our code so we cannot fix it, We are simply trying to get our code to co-exist with theirs. Thanks, Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
darrin
2008-May-29 13:31 UTC
Re: Multiple copies of Prototype.js cause errors in IE6 & IE7
I think this particular problem with getElementsByClassName is that there is a check to see if this method is already a native function by checking document.getElementsByClassName. On the first pass it sees that it is not and adds it to document and to Element.Methods. On the second pass it sees that it is already on document (from the first pass) and then does not add it to Element.Methods. It probably works in the other browsers because they can extend the prototype of DOM elements so the method "stuck" from the first pass. If you are putting widgets on your page that you don''t have control over it can you sandbox it in an iframe to avoid conflicts. I can imagine a lot worse conflicts than just duplicate libraries being loaded. Darrin On May 29, 4:24 am, BillyRayPreachersSon <BillyRayPreachers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Michael, > > We cannot rely on their copy because our page has a need for Prototype > before their widget is even invoked. > > Kangax, > > The error is simply "Object doesn''t support this property or method" > when trying to call the "getElementsByClassName" method on an element. > > Now, I know that "getElementsByClassName" has been deprecated, but > this isn''t our code so we cannot fix it, We are simply trying to get > our code to co-exist with theirs. > > Thanks, > Dan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---