0

I am using

function addEvent(element,myEvent,fnc)
{return((element.attachEvent)?element.attachEvent('on'+myEvent,fnc):element.addEventListener(myEvent,fnc,false));}

as detailed at addEventListener vs onclick .

Now to attach a click event to the window element I am using

addEvent(window,'click',myfunc);

where myfunc is a callback function. The problem is that IE 8 is not attaching the click event using this function how can I modify this function for IE 8 ? Thanks

Community
  • 1
  • 1
jahajee.com
  • 3,683
  • 4
  • 21
  • 26
  • Here's a tested `addEvent()`: http://stackoverflow.com/questions/10149963/adding-event-listener-cross-browser/10150042#10150042. I'm not sure what is wrong with yours. You would probably need to give a more detailed code example so people could see for themselves what isn't working. – jfriend00 Jul 27 '14 at 06:44
  • But that is the only minified code there is, from stackoverflow.com/questions/6348494/addeventlistener-vs-onclick 4th comment to accepted answer. Even the JS Fiddle which is linked there does not open in IE 8 :-( – jahajee.com Jul 27 '14 at 07:04
  • The fiddle works for me in IE8: http://jsfiddle.net/bmArj/153/show/ The editor at jsfiddle.net doesn't work with IE8(he doesn't even work without any content, so that's not related to the contents) – Dr.Molle Jul 27 '14 at 07:38
  • OK finally got it working with `document.onclick` instead of `window.onclick`, latter being not supported in IE 8. Thanks to [quirksmode](http://www.quirksmode.org/dom/events/click.html) for information. Also @Dr.Molle Trust you are right jsfiddle doesnot work in IE8 in general and it has nothing to do with the content. That remark from my side was irrelevant. Thank you all for the help. – jahajee.com Jul 27 '14 at 08:41
  • While I usually wouldn't say this, if you absolutely **have to** support IE8, do not roll your own event handling. Just grab jQuery. Several hundred people worked together on browser compatibility to solve this problem for you already. – Mike 'Pomax' Kamermans Jul 27 '14 at 08:44

0 Answers0