Good day! I have a form in the iframe, it needs to be sent on a specific event in the parent window. How to do it? I ask examples of js or js + jquery

    2 answers 2

    This is about how you can bind an event handler to an element in a frame.

    $('iframe').contents().find('body').bind('callmod',function(){ alert('Yahoooo!!!!'); }); 
    • An interesting option. Thank! - chuikoff
     <script> function changechild(){ var x = document.getElementById('fr'); var y = (x.contentWindow || x.contentDocument); y = y.document || y; y.body.innerHTML = "__works!__"; } </script> <input type="button" onclick="changechild()" value="change" id="bt"> <iframe src="test.html" id="fr"></iframe> test.html находится на том же домене 

    The second option: listen from the frame events from the parent document. Code to write?

    Added

    test.html:

     <script> var flag = 0; function doAction(){ flag = 1; } </script> <input type="button" onclick="doAction()" value="change" id="bt"> <iframe src="test2.html"></iframe> test2.html находится на том же домене 

    test2.html:

     <script> var flag = 0; function checkAction(){ if(window.parent.flag && !flag){ flag = 1; document.getElementById('bt').value = '__works!__'; } setTimeout(checkAction, 50); } checkAction(); </script> <input type="button" value="change" id="bt"> 
    • Come on! knowledge is not superfluous! - chuikoff