0

Is there a way to execute a javascript function on the second load of an iframe? Right now I am nesting two addEventListeners:

document.getElementById('my_iframe').addEventListener("load", function() {
    document.getElementById('my_iframe').addEventListener("load", doSomething(), true);
}, true);

The first "load" is triggered when I use document.my_iframe.write('...'). I want to trigger an action after I submit a form in the iframe, which is the second "load".

Is there a better way to accomplish my goal?

1 Answer 1

1

The event will fire each time the iframe is loaded no need for nesting, just for a counter.

var count;
element.addEventListener("load", function() {
    count++;
    if(count==2){
        //code goes here
    }
}, true); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.