jquery - How to handle nested event listeners javascript? (not about nested html elements) -


i need function trigger after 2 events. first event onload, , second onmessage coming iframe.

if onload , onmessage=="something"=> trigger that. otherwise => else.

however, seems onload executed before onmessage. need 2 event nested. (or not?)

shoud this:

     document.getelementbyid("myiframe").addeventlistener("load", iframeloaded, false);          function iframeloaded(){         window.top.addeventlistener("message", whatisthemessage, false);         }      function whatisthemessage(event){  window.top.removeeventlistener("message", whatisthemessage, false);      if(event.date=="something"){//do something}     else if(event.date=="somethingelse"){//do somethingelse}     } 

does seem correct? problem appear me if "message" arriving before (i think not not possible), don't listen it.

window.addeventlistener("load",test,false); window.addeventlistener("message",test,false); var counter=0;  function test(event){   counter++;   if(counter==2){    //two event listeners called   }  } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -