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);
        }
    }
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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.