initiate onclick event for FF and IE

sometimes there's a need to initiate an event.This perfectly works if FF doesn't work with event function such as .click().
function fireEvent(obj,evt) { 
   var fireOnThis = obj;
   if( document.createEvent ) {
      var evObj = document.createEvent('MouseEvents');
      evObj.initEvent( evt, true, false );
      fireOnThis.dispatchEvent(evObj);
   } else if( document.createEventObject ) {
      fireOnThis.fireEvent('on'+evt);
   }
}
function initiateEventCall(id) {
   if(navigator.appName == 'Microsoft Internet Explorer') {
      document.getElementById(id).click();
   } else {
      fireEvent(document.getElementById(id),'click');
   }
}

0 comments:

Post a Comment