Skip to content Skip to sidebar Skip to footer

Removeeventlistener Do Not Work In Firefox Ver 58

but it works in Chrome. Here is my code from UI_EventBus (prototype): (The addEventListener method is the same, but the remove is replaced with add.) UI_EventBus.removeEventListene

Solution 1:

The second argument to removeEventListener must be the function you want to remove.

You've put a function expression there, which will create a brand new function. As it is brand new, it can't have been previously added as an event listener.

Solution 2:

This is my updated code, if someone is interested in the solution:

UI_EventBus.listeners = [];

/* * ADD EVENT LISTENER */

UI_EventBus.addEventListener = function(target,  argEventType, obj, argEventHandler) {
    var element;;
    var strObj = target.toString();

    if(strObj.indexOf("HTML") >-1) 
        element = target;
    else
        element = target.getElement();




    varfunc= function(event){ 
        argEventHandler(event,obj); 
    };
    //console.log(" Add : " + target + "  " +  argEventType + " " + obj + " " +  argEventHandler + " " + func + " no of listeners " + UI_EventBus.listeners.length);

    element.addEventListener(argEventType,func);

    var listener = [target,argEventType, obj, argEventHandler, func];



    UI_EventBus.listeners.push(listener);


}
/*
 *   REMOVE EVENT LISTENER
 */UI_EventBus.removeEventListener = function(target, argEventType, obj, argEventHandler) {
    var element;;
    var strObj = target.toString();

    if(strObj.indexOf("HTML") >-1) 
        element = target;
    else
        element = target.getElement();



    var idx;
    varfunc;
    for(var i=0; i <UI_EventBus.listeners.length;i++)
        if(UI_EventBus.listeners[i][0] == target)
            //console.log("Obj " + UI_EventBus.listeners[i][0]);if(UI_EventBus.listeners[i][1] == argEventType)
                //console.log("Eventtype " + UI_EventBus.listeners[i][1]);if(UI_EventBus.listeners[i][2] == obj)
                    if(UI_EventBus.listeners[i][3] == argEventHandler){
                        //console.log("Handler " + UI_EventBus.listeners[i][2]);    func=UI_EventBus.listeners[i][4];
                        idx = i;
                        break;
                    }


    element.removeEventListener(argEventType,func);


    //console.log("no of listeners " + UI_EventBus.listeners.length + " idx=" + idx);//console.log(" Remove : " + UI_EventBus.listeners[i][0] + "  " +  UI_EventBus.listeners[i][1] + " " + UI_EventBus.listeners[i][2] + " " +  UI_EventBus.listeners[i][3] + " " +  UI_EventBus.listeners[i][4] );UI_EventBus.listeners.splice(idx,1);


}

Post a Comment for "Removeeventlistener Do Not Work In Firefox Ver 58"