2

I have several listeners like this, which listen to click and then displays content within <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 click (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 do nothing after click. Thank you 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);
}
5
  • What is the result of running alert(typeof google.maps.event.addListener)? Commented Jul 14, 2011 at 18:19
  • sorry for late response, i went to drink a beer. It displays single word : function Commented Jul 14, 2011 at 20:39
  • hmm. what about alert(typeof fireEvent)? Commented Jul 14, 2011 at 20:42
  • Then there's really not enough information in this question to be able to answer it. By the way - the fact that "it works" in chrome (despite displaying a javascript error in the debug console) doesn't mean that Chrome isn't experiencing this same problem. I'd wager that if you opened firebug in Firefox you'd also see a similar error. IE is simply sometimes more vocal about these errors. Commented Jul 14, 2011 at 21:09
  • Thank you for your effort digitalbath. Please, try to check www.turie.eu/hlavna2 where you can click on binoculars icon on the map ant it displays lightbox plugin in every browser except IE. Thank you very much! Commented Jul 14, 2011 at 21:19

2 Answers 2

2

You've got MooTools running on your page. MooTools overrides IE's built-in element.fireEvent() method with its own normalized method that works for all browsers. MooTools' version of fireEvent() expects "click" instead of "onclick".

You can fix this one issue by simply changing your 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 may be able to ditch your fireEvent function, and instead just call element.fireEvent() directly.

You may have bigger problems. You are using MooTools and jQuery side by side which is ok, but if you don't know what you are doing, you can get into trouble quickly.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you gilly3, your comment is very informative. I just solved it with return element[event](); instead of that line following /* for IE */. And you're right, I don't know exactly what I'm doing with mootools and jquery. The point is, that I don't know how mootools works, but I need it to run bumpbox (lightbox alternative) to display flash files. I plan using jQuery for everything else, because I have at least minimal skills with it and it seems easier to handle it for me. It was a challenge to make it work together and with other things, especially facebook comments plugin. Anyway, thans!
1

It's possible it's complaining because

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

is not a function. Where is the fireEvent function coming from?

2 Comments

Thank you shelman, I'm not very skilled with javascript. fireEvent was an advice from some person here in stackoverflow. Please check turie.eu/hlavna2 , there is a map.js with that function on line 817. And about 25 similar above, but it everytime complaining about the last one only..
shelman, I've edited my question and add fireEvent function. Hope that it hepls you to help me:) Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.