Tuesday, January 12, 2010

Firefox - Event handling issue

In the recent firefox releases 3.0 and 3.5, I see an issue in the event firing. In the ajax exvironment, it sometimes misfires.
In my scenario, for an anchor element, I kept the href attribute as "#" and added an onclick event for a clean solution.
aElem.href = "#";
aElem.onclick = function() {
//do the action
};

It is working fine in IE browser, but this event is not fired correctly in firefox browser.
When I click on the anchor element, firefox fires that action, but immediately after that it fires an event equivalent to refresh frame on which the anchor element was present.
To overcome this, I called the javascript function through the href attribute itself.
aElem.href="javascript:doMyAction();";

function doMyAction() {
// do the action
}

This is not a clean solution. But, this works both in firefox and IE.

No comments: