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
Post a Comment