0

I'm using the javascript code below to simulate a click on an iframe in Salesforce and hosted on my domain. I just want to simulate the first click on the iframe that's why i remove the event listner right after the iframe is clicked. But removing the event listner doesn't work. This function is called each the user click on the iframe. Do you know how i could achieve this ?

Thank you,

rerender : function( component, helper ) {

        this.superRerender();
        console.log('rerender');

        if(!$A.util.isUndefined(component.find('embeder'))){

            setTimeout(function(){component.find('input').focus()}, 10);

            var onBlurHandler = function(event) {

                setTimeout($A.getCallback(function() {

                    if(component.isValid()){

                        if(document.activeElement == document
                           .getElementsByTagName('iframe')[0])
                        {
                            helper.setTrackingData(component);
                        }

                    }

                }),0);
                removeEventListener('blur', onBlurHandler);

            };
            addEventListener("blur", onBlurHandler);
        }
    }

2 Answers 2

1

This HTML DOM removeEventListener() Method documentation says:

To remove event handlers, the function specified with the addEventListener() method must be an external function, like in the example above (myFunction).

Anonymous functions, like "element.removeEventListener("event", function(){ myScript });" will not work.

Not entirely clear what an "external function" is...

You could side-step the problem by leaving the handler in place but make it do nothing after the first invocation:

        var active = true;
        var onBlurHandler = function(event) {
            if (active) {
                ...
            }
            active = false;
        };
        addEventListener("blur", onBlurHandler);
0

external function means not an inner function. e.g. a function that returns a function is not a good idea because the returned function will have a different signature each time so addEventListener and removeEventListener will end up with 2 different functions :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .