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:

<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<script type="text/javascript" src="http://prototypejs.org/assets/
<title>A Simple Page</title>
<script type='text/javascript'>
Event.prototype.test = function() { //this line failed in IE8

document.observe('dom:loaded', function() {
        $('body').observe('click', function(e) {
<body id="body">
<p>Hi there</p>


* 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

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

T.J. Crowder
Independent Software Consultant
tj / crowder software / 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 
For more options, visit this group at 

Reply via email to