SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question IE doesn't like prototyping

    Hey guys,

    I'm having a problem with IE 7 (other versions didn't work either) when it comes to prototyping.

    This is the code:

    Code:
    <script language="javascript" type="text/javascript">
    function w2l_addListener(o, strEventType, funcCallback)
    {
    	if (o.addEventListener){//mozilla
    		o.addEventListener(strEventType, funcCallback, false);
    		return true;
    	}
    	else if(o.attachEvent){//IE
    		var r = o.attachEvent("on"+strEventType, funcCallback);
    		return r;
    	}
    	else{
        	return false;
    	}
    }
    
    Object.prototype.addListener = function(strEventType, funcCallback)
    {
    	w2l_addListener(this, strEventType, funcCallback);
    }
    
    window.addListener('load', initMouseOver);
    
    function initMouseOver()
    {
    	document.getElementById('test').addListener('mouseover', function(evnt){alert(evnt);});
    }

    The HTML-Body looks like this:
    Code:
    <div id="test" style="background-color: #CCCCCC;">Test</div>
    In Firefox and other Mozilla browsers it all works great but IE comes up with an error like this:
    "The object does not support this property or method in line x" whereas x refers to the line with "window.addListener('load', initMouseOver);".

    w2l_addListener(window, 'load', initMouseOver) which is the same really works fine, so the problem seems to be the prototyping as the same also happens with other functions I prototyped "Object" with (for adding css for instance).

    Has somebody encountered similiar problems and knows solution?

    Cheers, Florian

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DOM objects aren't native javascript objects in IE. Read this http://delete.me.uk/2004/09/ieproto.html for more info.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Thanks

    Hi,

    thanks a lot! I would have been stuck at this point for quite some time without that knowledge

    Thanks again, cheers, Florian


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •