thunderousNinja
thunderousNinja

Reputation: 3520

Event handler called twice (javascript)

I am new to JS and I am having some problems with my event handler being called twice for my bing map infobox. I assume it is because of mouseup and mousedown. However, I do not know how to check for whether the event is mouse up or mouse down (cant find it in the docs anywhere.) Anyone have any idea how to check if the mouseEvent is mouse up or mouse down? Here is a link to the docs for the infobox event handler: Bing Info Box docs

infoBox.setOptions({
                    actions : [ {
                        label : "Edit",
                        eventHandler : function(mouseEvent) {
                            // Called twice here...
                        }
                    } ]
                });

Upvotes: 0

Views: 333

Answers (1)

Nathan Wallace
Nathan Wallace

Reputation: 2264

I don't know anything about Bing Info Box, but assuming mouseEvent is the event object that triggered your handler, you could put a conditional in the event handler to process the event if it's a mousedown, but not if it's a mouseup:

...
eventHander : function(mouseEvent) {
  if (mouseEvent.type === "mousedown") {
    // do stuff
  }
}
...

EDIT

As indicated in the comment below, the way to achieve this with the Bing Info Box is to check if (mouseEvent.type === 'click')

Upvotes: 2

Related Questions