javascript - Error 0x800a01b6 - Object doesn't support property or method 'attachEvent' -


i'm new in field , don't know why it's wrong:

if (this.trigger.addeventlistener) {             this.trigger.addeventlistener(this.eventtype, function (ev) {                 ev.stoppropagation();                 ev.preventdefault();                 if (self.ismenuopen) {                     self._closemenu();                     document.removeeventlistener(self.eventtype, self.bodyclickfn);                 }                 else {                     self._openmenu();                     document.addeventlistener(self.eventtype, self.bodyclickfn);                 }             });         } else {             this.trigger.attachevent('on' + this.eventtype, function (ev) {                 ev.stoppropagation();                 ev.preventdefault();                 if (self.ismenuopen) {                     self._closemenu();                     document.detachevent('on' + self.eventtype, self.bodyclickfn);                 }                 else {                     self._openmenu();                     document.attachevent('on' + self.eventtype, self.bodyclickfn);                 }             }); 

the addeventlistener works fine in ie edge, chrome, ff need working in ie7 , don't find similar example on friend google.

thanks in advanced.

the problem in access element:

if (msieversion() <= 7) {             this.trigger = document.getelementbyid('t123');             this.menu = document.getelementbyid('t456');          } else {             this.trigger = this.el.queryselector('a.gn-icon-menu');             this.menu = this.el.queryselector('nav.gn-menu-wrapper');         } 

and methods ev.stoppropagation(); , ev.preventdefault(); don't supported ie7. right way:

(ev.stoppropagation) ? ev.stoppropagation() : ev.cancelbubble=true ; (ev.preventdefault) ? ev.preventdefault() : ev.returnvalue = false; 

thanks everyone.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -