Event handling different for IE vs Firefox vs Chrome

2,367 views
Skip to first unread message

DaveCline

unread,
Jun 11, 2012, 4:09:24 PM6/11/12
to javascript-information...@googlegroups.com
Tribe,

I'm using the TreeMap.

I'm adding buttons to cells:

onCreateLabel: function (domElement, node) {

  //.. other code
var html = "<input type='button' value='!' id='IDhere' onClick='showAlertsPopup(this,\"" + node.id + "\");' class='alertBtn'/>";
  domElement.innerHTML = html;
domElement.node = node;
  //... other code

In showAlertsPopup I add a DIV dialog to the body to show a message.

The issue I'm having is that the onclick event of the button in combination with the treemap's cell click, is behaving poorly in FireFox. In IE and Chrome and Safari the button gets the click first - I handle it, and cancel any propagation beyond the button. In Firefox however, the cell gets the click first, which drills into the cell, and then the button gets the click event. I don't want to drill when the button is clicked.

Is there a way to reverse the event attachments for FireFox? Or supersede the event sequence so that the button always get the event first?

Thanks for any pointers or help
-dc

DaveCline

unread,
Jun 11, 2012, 4:44:26 PM6/11/12
to javascript-information...@googlegroups.com
Nevermind. I found the issue.

In the onClick event for the cell, I had not included the middle object in the call. Once I put the "event" parameter as the 3rd in the series then I could cancel the drill down:

var onClickFunctionObject = function (node, someObject, event) {
if ((event && event.target && event.target.type == 'button')  || 
      (window.event && window.event.srcElement && window.event.srcElement.type == 'button'))
   return;

//.. stuff

Events: {                    // Attach left and right click events
enable: true,
onClick: onClickFunctionObject,
  onRightClick: onRightClickFunctionObject
}


I had not included the "someObject" which I have no idea want it actually is... But the event argument is now in the right place and I get correct behavior for all browsers now.

Firefox was handling the events in the order they were added to the dom elements and not in the reverse order that IE/chrome/safari were. That's why it worked in IE/Chrome/Safari but not FF.

-dc
Reply all
Reply to author
Forward
0 new messages