CONTE...">

JavaScript Error "Function Expected"

I have several listeners that listen for a click and then display the content in <div id="c50"><a hre...>CONTENT</a></div> (in this case). Everything works in Opera, Chrome and FF, but not in IE.

 google.maps.event.addListener(pano50, 'click', function() { fireEvent(document.getElementById("c50").getElementsByTagName("a")[0], 'click'); }) 

Chrome javascript console tool displays this error after clicking (but works fine):

 Uncaught TypeError: object is not a function 

but traditionally IE8 displays:

 Function expected on line 817 

which is the first line of code above and does nothing after a click. Thanks for any advice!

EDIT: here is the fireEvent function:

 function fireEvent(element, event) { if (document.createEventObject){ /* for IE */ return element.fireEvent('on' + event, document.createEventObject()); }else{ /* for other browsers */ var evt = document.createEvent('HTMLEvents'); evt.initEvent(event, true, true); } return !element.dispatchEvent(evt); } 
+2
source share
2 answers

You have MooTools running on your page . MooTools overrides IE's built-in element.fireEvent() method with its own normalized method , which works for all browsers. The MooTools version of fireEvent() expects a "click" instead of an "onclick".

You can fix this problem by simply changing the fireEvent function to use "click" instead of "onclick":

 /* for IE */ return element.fireEvent(event, document.createEventObject()); 

But since MooTools normalizes element.fireEvent to work with all browsers, you can disable the fireEvent function, and instead just call element.fireEvent() directly.

You may have big problems. You use MooTools and jQuery side by side, which is good, but if you do not know what you are doing, you can quickly get into the problem.

+2
source

Perhaps he complains because

document.getElementById("c50").getElementsByTagName("a")[0]

not a function. Where does the fireEvent function come from?

+1
source

Source: https://habr.com/ru/post/1481449/


All Articles