Hi T.J, thank you very much! On Fri, Mar 19, 2010 at 6:35 PM, T.J. Crowder <t...@crowdersoftware.com>wrote:
> Hi, > > These days, for any advanced scripting you really need to have a > doctype on the page to ensure that browsers are in standards mode > (IMHO). Specifically in this case, putting a doctype on the page > corrects the problem (I don't know why). You also need to put > something in the body, or you'll have nowhere to click (on IE the body > doesn't automatically have any height). > > There were some other changes to that page I'd make (and which the W3C > validator page[1] would suggest); here's what I'd do: > > <!DOCTYPE HTML> > <html> > <head> > <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> > <script type="text/javascript" src="http://prototypejs.org/assets/ > 2009/8/31/prototype.js"></script> > <title>A Simple Page</title> > <script type='text/javascript'> > Event.prototype.test = function() { //this line failed in IE8 > alert(this.type); > }; > > document.observe('dom:loaded', function() { > $('body').observe('click', function(e) { > e.test(); > }); > }); > </script> > </head> > <body id="body"> > <p>Hi there</p> > </body> > </html> > > Changes: > > * Add a doctype -- the doctype above is for HTML5, which I'd recommend > any time you can avoid using XHTML (which is most of the time) > * Add a charset declaration > * Use type="text/javascript" rather than language="javascript" for the > script tag with your custom script > * Remove the comment markers from around the JavaScript, they're > unnecessary > > Obviously this was just a test page, but when running into odd issues, > ensuring that the test page is valid actually can make a > difference. :-) > > [1] http://validator.w3.org > > HTH, > -- > T.J. Crowder > Independent Software Consultant > tj / crowder software / com > www.crowdersoftware.com > > On Mar 19, 12:59 am, green <greenlaw...@gmail.com> wrote: > > Hi > > > > I am trying to extend prototype Event object by adding a new method, a > very > > simple html file demonstrate what I was doing: > > > > <html> > > <head> > > <script type="text/javascript" src=" > http://prototypejs.org/assets/2009/8/31/prototype.js"></script> > > <title>A Simple Page</title> > > <script language="JavaScript"> > > <!-- > > Event.prototype.test = function() { //this line failed in IE8 > > alert(this.type);}; > > > > document.observe('dom:loaded', function() { > > $('body').observe('click', function(e) {e.test();});}); > > > > --> > > </script> > > </head> > > <body id="body"> > > </body> > > </html> > > > > This file works fine in firefox and chrome, however it failed in IE8 with > > error message: 'Event.prototype' is null or not an object. Can someone > help > > out? > > > > Thx, > > Green > > -- > 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-scriptacul...@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > > -- 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-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.