开发者

Execute a javascript function on the second load of an iframe

开发者 https://www.devze.com 2023-02-21 11:32 出处:网络
Is there a way to execute a javascript function on the second load of an iframe? Right now I am nesting two addEventList开发者_运维技巧eners:

Is there a way to execute a javascript function on the second load of an iframe? Right now I am nesting two addEventList开发者_运维技巧eners:

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?


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

精彩评论

暂无评论...
验证码 换一张
取 消